func TestFilespaceConverter_FromMultipart(t *testing.T) { memFilespace, err := memfs.NewFilespace() if err != nil { t.Error(err) return } converter := NewFilespaceConverter(memFilespace) fh := mockmultipart.NewFileHeader([]byte(TestFileContent)) iInterface, err := converter.FromMultipart(fh) if err != nil { t.Error(err) return } file, ok := iInterface.(types.File) if !ok { t.Errorf("converter.FromString result is not types.File instance %v", file) return } fileContent, err := file.Filespace().ReadFile(file.Path()) if err != nil { t.Error(err) return } if !testbase.ByteArrayEq(fileContent, []byte(TestFileContent)) { t.Errorf("converter.FromString result is not types.File instance \n%v \n !=\n %v", string(fileContent), TestFileContent) return } }
func TestStringConverter_FromMultipart(t *testing.T) { fh := mockmultipart.NewFileHeader([]byte("11")) converter := StringConverter{} iInterface, err := converter.FromMultipart(fh) if err != nil { t.Error(err) return } iv := iInterface.(string) if iv != "11" { t.Errorf("From string can not convert 11, result is %v", iv) return } }
func TestObjectConverter_FromMultipart(t *testing.T) { fh := mockmultipart.NewFileHeader([]byte(TestObjectJSON)) converter := NewObjectConverter(NewTestObject) iInterface, err := converter.FromMultipart(fh) if err != nil { t.Error(err) return } o := iInterface.(*TestObject) if o.A != "value" { t.Errorf("A should be 'value', result is %v", o) return } }
func TestInt64Converter_FromMultipart(t *testing.T) { fh := mockmultipart.NewFileHeader([]byte("11")) ic := Int64Converter{} iInterface, err := ic.FromMultipart(fh) if err != nil { t.Error(err) return } iv, ok := iInterface.(int64) if !ok { t.Errorf("can not convert to int64: %v", iv) return } if iv != 11 { t.Errorf("From multipart can not convert 11, result is %v", iv) return } }