package
0.0.0-20250105235550-d74b9e249dd3
Repository: https://github.com/muchq/moonbase.git
Documentation: pkg.go.dev

# README

Clock

Use the clock interface to access time.Time so that modules stay testable.

Examples

prod:

type Foo struct {
    Clock Clock
}

func (f *Foo) SecondsSinceEpochIsEven() bool {
    return f.Clock().Unix() % 2 == 0
}

func main() {
    foo := &Foo{
        Clock: NewSystemUtcClock(),
    }
	
    fmt.PrintLn(foo.SecondsSinceEpochIsEven())
}

test:

func TestFoo_SecondsSinceEpochIsEven(t * testing.T) {
    testClock := NewTestClock()
    foo := &Foo{
        Clock: testClock,
    }
	
    assert.True(t, foo.SecondsSinceEpochIsEven(), "zero is even")
    
    testClock.Tick(1)
    assert.False(t, foo.SecondsSinceEpochIsEven(), "1 is odd")
}

# Functions

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
TestClock is a Clock implementation for use in tests.

# Interfaces

No description provided by the author