github.com/mithrandie/csvq@v1.18.1/lib/option/static_test.go (about) 1 package option 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestGetRand(t *testing.T) { 9 p1 := GetRand() 10 p2 := GetRand() 11 12 if p1 != p2 { 13 t.Errorf("function GetRand() returns different pointer") 14 } 15 } 16 17 func TestGetLocation(t *testing.T) { 18 p1, _ := GetLocation("Local") 19 p2, _ := GetLocation("Local") 20 21 if p1 != p2 { 22 t.Error("function GetLocation() returns different pointer") 23 } 24 25 _, err := GetLocation("Err") 26 if err == nil { 27 t.Error("function GetLocation() must return an error") 28 } else if err.Error() != "timezone \"Err\" does not exist" { 29 t.Errorf("function GetLocation() returned an error %q, want %q", err.Error(), "timezone \"Err\" does not exist") 30 } 31 32 } 33 34 func TestNow(t *testing.T) { 35 loc, _ := GetLocation("UTC") 36 TestTime, _ = time.ParseInLocation("2006-01-02 15:04:05.999999999", "2012-02-01 12:03:23", loc) 37 38 expect := time.Date(2012, 2, 1, 12, 3, 23, 0, loc) 39 40 if !Now(loc).Equal(expect) { 41 t.Errorf("function Now() returns current time") 42 t.Log(Now(loc)) 43 } 44 45 TestTime = time.Time{} 46 if Now(loc).Equal(expect) { 47 t.Errorf("function Now() returns fixed time") 48 t.Log(Now(loc)) 49 } 50 51 }