This library contains interface and set of implementations for getting current time. For production usage time must be mostly real time. For testing purposes it's often much easier to use mocked time so it will return required time each time.
The project is tested with go 1.9 but probably will work with earlier versions.
Simple go get it
go get github.com/anothermemory/clockpackage clock_test
import (
"time"
"github.com/anothermemory/clock"
)
func ExampleMock() {
var dummyTime = time.Date(2017, 11, 24, 17, 0, 0, 0, time.Local)
c := clock.NewMock(dummyTime)
c.Now() // Will return dummyTime each time
}
func ExampleMockPartial() {
firstTime := time.Date(2017, 11, 24, 17, 0, 0, 0, time.Local)
secondTime := time.Date(2018, 11, 24, 17, 0, 0, 0, time.Local)
c := clock.NewMockPartial(firstTime, secondTime)
c.Now() // This will return firstTime
c.Now() // This will return secondTime
c.Now() // This will return real time
}package clock_test
import (
"time"
"github.com/anothermemory/clock"
)
func ExampleReal() {
c := clock.NewReal()
c.Now() // Will return real current time
}- dep - The dependency management tool for Go
Please read CODE_OF_CONDUCT.md for details on our code of conduct, and CONTRIBUTING.md for details on the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Vyacheslav Enis
See also the list of contributors who participated in this project.
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details