Skip to content

Commit

Permalink
test: split Unmarshal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GGXXLL committed Jul 29, 2021
1 parent 42644dc commit 00504a7
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions config/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,40 @@ func TestDuration_UnmarshalJSON(t *testing.T) {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
v1 := Duration{}
yaml.Unmarshal([]byte(c.value), &v1)
assert.Equal(t, c.expected, v1)
v2 := Duration{}
json.Unmarshal([]byte(c.value), &v2)
assert.Equal(t, c.expected, v2)
d := Duration{}
err := json.Unmarshal([]byte(c.value), &d)
assert.NoError(t, err)
assert.Equal(t, c.expected, d)
})
}
}

func TestDuration_UnmarshalYaml(t *testing.T) {
var cases = []struct {
name string
value string
expected Duration
}{
{
"simple",
`"5s"`,
Duration{5 * time.Second},
},
{
"float",
`65000000000.0`,
Duration{5*time.Second + time.Minute},
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
d := Duration{}
err := yaml.Unmarshal([]byte(c.value), &d)
assert.NoError(t, err)
assert.Equal(t, c.expected, d)
})
}
}
Expand Down Expand Up @@ -93,6 +121,7 @@ func TestDuration_IsZero(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
d := Duration{tt.val}
if got := d.IsZero(); got != tt.want {
t.Errorf("IsZero() = %v, want %v", got, tt.want)
Expand Down

0 comments on commit 00504a7

Please sign in to comment.