diff options
Diffstat (limited to 'model/utils_test.go')
-rw-r--r-- | model/utils_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/model/utils_test.go b/model/utils_test.go index d35146b30..f004fc216 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -4,9 +4,11 @@ package model import ( + "fmt" "net/http" "strings" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -30,6 +32,39 @@ func TestRandomString(t *testing.T) { } } +func TestGetMillisForTime(t *testing.T) { + thisTimeMillis := int64(1471219200000) + thisTime := time.Date(2016, time.August, 15, 0, 0, 0, 0, time.UTC) + + result := GetMillisForTime(thisTime) + + if thisTimeMillis != result { + t.Fatalf(fmt.Sprintf("millis are not the same: %d and %d", thisTimeMillis, result)) + } +} + +func TestParseDateFilterToTimeISO8601(t *testing.T) { + testString := "2016-08-01" + compareTime := time.Date(2016, time.August, 1, 0, 0, 0, 0, time.UTC) + + result := ParseDateFilterToTime(testString) + + if result != compareTime { + t.Fatalf(fmt.Sprintf("parsed date doesn't match the expected result: parsed result %v and expected time %v", result, compareTime)) + } +} + +func TestParseDateFilterToTimeNeedZeroPadding(t *testing.T) { + testString := "2016-8-1" + compareTime := time.Date(2016, time.August, 1, 0, 0, 0, 0, time.UTC) + + result := ParseDateFilterToTime(testString) + + if result != compareTime { + t.Fatalf(fmt.Sprintf("parsed date doesn't match the expected result: parsed result %v and expected time %v", result, compareTime)) + } +} + func TestAppError(t *testing.T) { err := NewAppError("TestAppError", "message", nil, "", http.StatusInternalServerError) json := err.ToJson() |