https://github.com/sandwich-go/xtime
mock time
https://github.com/sandwich-go/xtime
golang mock testing time
Last synced: about 1 year ago
JSON representation
mock time
- Host: GitHub
- URL: https://github.com/sandwich-go/xtime
- Owner: sandwich-go
- Created: 2022-02-10T05:46:22.000Z (over 4 years ago)
- Default Branch: 0.1/release
- Last Pushed: 2024-07-16T12:49:13.000Z (almost 2 years ago)
- Last Synced: 2025-04-07T00:28:01.024Z (about 1 year ago)
- Topics: golang, mock, testing, time
- Language: Go
- Homepage:
- Size: 58.6 KB
- Stars: 5
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG-0.1.md
Awesome Lists containing this project
README
# xtime
模拟Golang标准库Time接口,提供Freeze,Travel等功能。
Run xtime Example: [](https://repl.it//@timestee/XTime#main.go)
```golang
type Clock interface {
After(d time.Duration) <-chan time.Time
Now() time.Time
Since(t time.Time) time.Duration
Until(t time.Time) time.Duration
Sleep(d time.Duration)
Tick(d time.Duration) <-chan time.Time
NewTicker(d time.Duration) *MockTicker
Timer(d time.Duration) *MockTimer
AfterFunc(d time.Duration, f func()) *MockTimer
WithDeadline(parent context.Context, d time.Time) (context.Context, context.CancelFunc)
WithTimeout(parent context.Context, t time.Duration) (context.Context, context.CancelFunc)
}
type Cop interface {
Freeze(t time.Time)
Travel(t time.Time)
Scale(scale float64)
Return()
ApplyOption(...Option) []Option
}
type Mock interface {
Clock
Cop
}
```