mirror of https://github.com/poanetwork/gecko.git
Merge pull request #36 from moreati/utils-clock_test
utils: Add unit tests for clocks
This commit is contained in:
commit
6c549d1504
|
@ -0,0 +1,37 @@
|
|||
package timer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClockSet(t *testing.T) {
|
||||
clock := Clock{}
|
||||
clock.Set(time.Unix(1000000, 0))
|
||||
if clock.faked == false {
|
||||
t.Error("Fake time was set, but .faked flag was not set")
|
||||
}
|
||||
if !clock.Time().Equal(time.Unix(1000000, 0)) {
|
||||
t.Error("Fake time was set, but not returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClockSync(t *testing.T) {
|
||||
clock := Clock{true, time.Unix(0, 0)}
|
||||
clock.Sync()
|
||||
if clock.faked == true {
|
||||
t.Error("Clock was synced, but .faked flag was set")
|
||||
}
|
||||
if clock.Time().Equal(time.Unix(0, 0)) {
|
||||
t.Error("Clock was synced, but returned a fake time")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClockUnix(t *testing.T) {
|
||||
clock := Clock{true, time.Unix(-14159040, 0)}
|
||||
actual := clock.Unix()
|
||||
if actual != 0 {
|
||||
// We are Unix of 1970s, Moon landings are irrelevant
|
||||
t.Errorf("Expected time prior to Unix epoch to be clamped to 0, got %d", actual)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue