Skip to content

Commit

Permalink
Merge pull request #9 from xmidt-org/feature/check-system-clock
Browse files Browse the repository at this point in the history
Feature/check system clock
  • Loading branch information
johnabass authored Oct 14, 2021
2 parents 4d8054d + 07c620a commit 71c81d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- IsSystemClock for verifying production code initialization

## [v0.1.0]
- basic examples
Expand Down
8 changes: 8 additions & 0 deletions systemClock.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ func (sc systemClock) NewTimer(d time.Duration) Timer {
func SystemClock() Clock {
return systemClock{}
}

// IsSystemClock tests if c is actually a Clock returned by SystemClock().
// This function is primarily useful in test code to verify that production
// code correctly initializes itself.
func IsSystemClock(c Clock) bool {
_, ok := c.(systemClock)
return ok
}
10 changes: 10 additions & 0 deletions systemClock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ func (suite *SystemClockSuite) TestNewTicker() {
suite.requireSignal(t.C(), 16*time.Millisecond)
}

func (suite *SystemClockSuite) TestIsSystemClock() {
suite.True(
IsSystemClock(SystemClock()),
)

suite.False(
IsSystemClock(NewFakeClock(time.Now())),
)
}

func TestSystemClock(t *testing.T) {
suite.Run(t, new(SystemClockSuite))
}

0 comments on commit 71c81d0

Please sign in to comment.