Add int slice test to unmarshal

This commit is contained in:
Mark Sagi-Kazar 2019-01-27 03:26:12 +01:00
parent b52b215be2
commit b267a43b23
No known key found for this signature in database
GPG key ID: 34CC109EB5ED1C2A

View file

@ -516,11 +516,13 @@ func TestUnmarshal(t *testing.T) {
SetDefault("port", 1313) SetDefault("port", 1313)
Set("name", "Steve") Set("name", "Steve")
Set("duration", "1s1ms") Set("duration", "1s1ms")
Set("modes", []int{1, 2, 3})
type config struct { type config struct {
Port int Port int
Name string Name string
Duration time.Duration Duration time.Duration
Modes []int
} }
var C config var C config
@ -530,14 +532,33 @@ func TestUnmarshal(t *testing.T) {
t.Fatalf("unable to decode into struct, %v", err) t.Fatalf("unable to decode into struct, %v", err)
} }
assert.Equal(t, &config{Name: "Steve", Port: 1313, Duration: time.Second + time.Millisecond}, &C) assert.Equal(
t,
&config{
Name: "Steve",
Port: 1313,
Duration: time.Second + time.Millisecond,
Modes: []int{1, 2, 3},
},
&C,
)
Set("port", 1234) Set("port", 1234)
err = Unmarshal(&C) err = Unmarshal(&C)
if err != nil { if err != nil {
t.Fatalf("unable to decode into struct, %v", err) t.Fatalf("unable to decode into struct, %v", err)
} }
assert.Equal(t, &config{Name: "Steve", Port: 1234, Duration: time.Second + time.Millisecond}, &C)
assert.Equal(
t,
&config{
Name: "Steve",
Port: 1234,
Duration: time.Second + time.Millisecond,
Modes: []int{1, 2, 3},
},
&C,
)
} }
func TestUnmarshalWithDecoderOptions(t *testing.T) { func TestUnmarshalWithDecoderOptions(t *testing.T) {