Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Add test cases for binding parseTime
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed90 committed Jul 15, 2018
1 parent 16b9e07 commit 686cf12
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,36 @@ func TestParseTimeErrorParsing(t *testing.T) {
}

func TestParseTime(t *testing.T) {

r := require.New(t)
tt, err := parseTime([]string{"2017-01-01"})
r.NoError(err)
expected := time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC)
r.Equal(expected, tt)

testCases := []struct {
input string
expected time.Time
expectErr bool
}{
{
input: "2017-01-01",
expected: time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC),
expectErr: false,
},
{
input: "2018-07-13T15:34",
expected: time.Date(2018, time.July, 13, 15, 34, 0, 0, time.UTC),
expectErr: false,
},
{
input: "2018-20-10T30:15",
expected: time.Time{},
expectErr: true,
},
}

for _, tc := range testCases {
tt, err := parseTime([]string{tc.input})
if !tc.expectErr {
r.NoError(err)
}
r.Equal(tc.expected, tt)
}
}

0 comments on commit 686cf12

Please sign in to comment.