1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package config
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestEndpointMode_SetFromString(t *testing.T) {
cases := map[string]struct {
Value string
Expect EndpointModeState
WantErr bool
}{
"empty value": {
Expect: EndpointModeStateUnset,
},
"unknown value": {
Value: "foobar",
WantErr: true,
},
"IPv4": {
Value: "IPv4",
Expect: EndpointModeStateIPv4,
},
"IPv6": {
Value: "IPv6",
Expect: EndpointModeStateIPv6,
},
"IPv4 case-insensitive": {
Value: "iPv4",
Expect: EndpointModeStateIPv4,
},
"IPv6 case-insensitive": {
Value: "iPv6",
Expect: EndpointModeStateIPv6,
},
}
for name, tt := range cases {
t.Run(name, func(t *testing.T) {
var em EndpointModeState
if err := em.SetFromString(tt.Value); (err != nil) != tt.WantErr {
t.Fatalf("WantErr=%v, got err=%v", tt.WantErr, err)
}
if diff := cmp.Diff(em, tt.Expect); len(diff) > 0 {
t.Errorf(diff)
}
})
}
}
|