diff --git a/go/internal/statsrelay/statsrelay.go b/go/internal/statsrelay/statsrelay.go index 44c81f515..2610de8f6 100644 --- a/go/internal/statsrelay/statsrelay.go +++ b/go/internal/statsrelay/statsrelay.go @@ -102,6 +102,13 @@ func New(relay string, key ohttp.KeyConfig, client *http.Client) *Client { return &Client{relay: relay, key: key, http: client, now: time.Now} } +// WithClock makes c stamp reports with the day now reads. Tests pin it to +// the fake gateway's clock, so a fixed test date stays fresh. +func (c *Client) WithClock(now func() time.Time) *Client { + c.now = now + return c +} + // Relay is the relay's URL, for Settings. func (c *Client) Relay() string { return c.relay } diff --git a/go/internal/statsrelay/statsrelaytest/statsrelaytest.go b/go/internal/statsrelay/statsrelaytest/statsrelaytest.go index 1a30e5bfa..bee5e374a 100644 --- a/go/internal/statsrelay/statsrelaytest/statsrelaytest.go +++ b/go/internal/statsrelay/statsrelaytest/statsrelaytest.go @@ -86,7 +86,7 @@ func New(t testing.TB, now time.Time) (*statsrelay.Client, *Gateway, *Relay) { _, _ = io.Copy(w, resp.Body) })) t.Cleanup(rl.Close) - return statsrelay.New(rl.URL, g.Key, nil), g, rl + return statsrelay.New(rl.URL, g.Key, nil).WithClock(func() time.Time { return now }), g, rl } func (g *Gateway) add(msg []byte) int {