Files
excelConverter/pkg/set/set_test.go
2021-02-28 08:33:00 +01:00

38 lines
820 B
Go

package set
import "testing"
func TestField(t *testing.T) {
input := struct {
MyString string
MyInt int
MyFloat float64
MyBool bool
}{}
value := "abc"
Field(&input, "MyString", value)
if input.MyString != value {
t.Errorf("got: %s; want: %s", input.MyString, value)
}
err := Field(&input, "MyFloat", "3.14")
if err != nil {
t.Error("expect no error, when can be converted")
}
if input.MyFloat != 3.14 {
t.Errorf("MyFloat is not 3.14. Got: %#v", input.MyFloat)
}
err = Field(&input, "MyInt", "vInt")
if err == nil {
t.Error("expect error, when wrong value-Type")
}
err = Field(&input, "MyInt", "3")
if err != nil {
t.Error("expect no error, when can be converted")
}
err = Field(&input, "NoField", "jjj")
if err == nil {
t.Error("expect error, when field not exists")
}
}