Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func After ¶
Example ¶
package main import ( "testing" "time" "go.llib.dev/testcase/clock" "go.llib.dev/testcase/clock/timecop" ) func main() { var tb testing.TB timecop.SetSpeed(tb, 5) // 5x time speed <-clock.After(time.Second) // but only wait 1/5 of the time }
func Now ¶ added in v0.154.0
Now returns the current time. Time returned by Now is affected by time travelling.
Example ¶
package main import ( "go.llib.dev/testcase/clock" ) func main() { now := clock.Now() _ = now }
func Sleep ¶
Example ¶
package main import ( "testing" "time" "go.llib.dev/testcase/clock" "go.llib.dev/testcase/clock/timecop" ) func main() { var tb testing.TB timecop.SetSpeed(tb, 5) // 5x time speed clock.Sleep(time.Second) // but only sleeps 1/5 of the time }
func TimeNow ¶
TimeNow is an alias for clock.Now
Example (Freeze) ¶
package main import ( "testing" "time" "go.llib.dev/testcase/assert" "go.llib.dev/testcase/clock" "go.llib.dev/testcase/clock/timecop" ) func main() { var tb testing.TB type Entity struct { CreatedAt time.Time } MyFunc := func() Entity { return Entity{ CreatedAt: clock.Now(), } } expected := Entity{ CreatedAt: clock.Now(), } timecop.Travel(tb, expected.CreatedAt, timecop.Freeze) assert.Equal(tb, expected, MyFunc()) }
Example (WithTravelByDate) ¶
package main import ( "testing" "time" "go.llib.dev/testcase/clock" "go.llib.dev/testcase/clock/timecop" ) func main() { var tb testing.TB date := time.Date(2022, 01, 01, 12, 0, 0, 0, time.Local) timecop.Travel(tb, date, timecop.Freeze) // freeze the time until it is read time.Sleep(time.Second) _ = clock.Now() // equals with date }
Example (WithTravelByDuration) ¶
package main import ( "testing" "time" "go.llib.dev/testcase/clock" "go.llib.dev/testcase/clock/timecop" ) func main() { var tb testing.TB _ = clock.Now() // now timecop.Travel(tb, time.Hour) _ = clock.Now() // now + 1 hour }
Types ¶
Click to show internal directories.
Click to hide internal directories.