func TestNow(t *testing.T) { runtime.SetFaketime(goday) defer runtime.SetFaketime(0) start := time.Now() time.Sleep(10 * time.Millisecond) sleep := time.Now().Sub(start) if sleep != 10*time.Millisecond { t.Fatalf("Sleep expected: %v but was: %v!", 10*time.Millisecond, sleep) } }
func TestRuntimeFaketimeWorks(t *testing.T) { // like the Go Playground (https://blog.golang.org/playground) // we like to set the faketime to 2009-11-10 23:00:00 +0000 UTC runtime.SetFaketime(goday) defer runtime.SetFaketime(0) now := time.Now().UnixNano() // unix timestamp 1257894000 fmt.Printf("%v", time.Now()) fmt.Printf("%v", now) if now != goday { t.Fatalf("Time expected: %v but was: %v!", goday, now) } }