github.com/michael-k/docker@v1.7.0-rc2/pkg/timeutils/utils_test.go (about) 1 package timeutils 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetTimestamp(t *testing.T) { 8 cases := []struct{ in, expected string }{ 9 {"0", "-62167305600"}, // 0 gets parsed year 0 10 11 // Partial RFC3339 strings get parsed with second precision 12 {"2006-01-02T15:04:05.999999999+07:00", "1136189045"}, 13 {"2006-01-02T15:04:05.999999999Z", "1136214245"}, 14 {"2006-01-02T15:04:05.999999999", "1136214245"}, 15 {"2006-01-02T15:04:05", "1136214245"}, 16 {"2006-01-02T15:04", "1136214240"}, 17 {"2006-01-02T15", "1136214000"}, 18 {"2006-01-02T", "1136160000"}, 19 {"2006-01-02", "1136160000"}, 20 {"2006", "1136073600"}, 21 {"2015-05-13T20:39:09Z", "1431549549"}, 22 23 // unix timestamps returned as is 24 {"1136073600", "1136073600"}, 25 26 // String fallback 27 {"invalid", "invalid"}, 28 } 29 30 for _, c := range cases { 31 o := GetTimestamp(c.in) 32 if o != c.expected { 33 t.Fatalf("wrong value for '%s'. expected:'%s' got:'%s'", c.in, c.expected, o) 34 } 35 } 36 }