Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions go/internal/statsrelay/statsrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion go/internal/statsrelay/statsrelaytest/statsrelaytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading