31 lines
615 B
Go
31 lines
615 B
Go
package set
|
|
|
|
import "testing"
|
|
|
|
func TestField(t *testing.T) {
|
|
input := struct {
|
|
MyString string
|
|
MyInt int
|
|
MyBool bool
|
|
}{}
|
|
value := "abc"
|
|
Field(&input, "MyString", value)
|
|
if input.MyString != value {
|
|
t.Errorf("got: %s; want: %s", input.MyString, value)
|
|
}
|
|
vInt := 2
|
|
Field(&input, "MyInt", vInt)
|
|
if input.MyInt != vInt {
|
|
t.Errorf("MyInt: %d, want: %d", input.MyInt, vInt)
|
|
}
|
|
err := Field(&input, "MyInt", "vInt")
|
|
if err == nil {
|
|
t.Error("expect error, when wrong value-Type")
|
|
}
|
|
err = Field(&input, "NoField", "jjj")
|
|
if err == nil {
|
|
t.Error("expect error, when field not exists")
|
|
}
|
|
|
|
}
|