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 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 ¶
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.TimeNow(),
}
}
expected := Entity{
CreatedAt: clock.TimeNow(),
}
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.TimeNow() // 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.TimeNow() // now
timecop.Travel(tb, time.Hour)
_ = clock.TimeNow() // now + 1 hour
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.