mirror of
https://github.com/spf13/viper
synced 2025-05-07 12:47:18 +00:00
Add int slice test to unmarshal
This commit is contained in:
parent
b52b215be2
commit
b267a43b23
1 changed files with 23 additions and 2 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue