converge/pkg/support/throttling/utils_test.go
Erik Brakkee 52160a368c more generalization of how time is handled in the tests.
Asynchronous variant that is easier to use and multi-thread safe.
2024-08-16 21:08:44 +02:00

28 lines
434 B
Go

package throttling
import (
"os"
"testing"
"time"
)
type testClock struct {
now time.Time
}
func (t *testClock) time() time.Time {
return t.now
}
// Set this value to obtain a new value for the current time.
// This allows testing various scenario's with timing.
var currentTime = &testClock{}
func TestMain(m *testing.M) {
oldclock := clock
clock = currentTime
exitCode := m.Run()
clock = oldclock
os.Exit(exitCode)
}