Skip to content

Commit

Permalink
Add helper function for parsing time in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Nov 13, 2023
1 parent 470dfc0 commit 2c1586c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/bloomgateway/bloomgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func parseDayTime(s string) config.DayTime {
}
}

func mktime(s string) model.Time {
ts, err := time.Parse("2006-01-02 15:04", s)
if err != nil {
panic(err)
}
return model.TimeFromUnix(ts.Unix())
}

func groupRefs(t *testing.T, chunkRefs []*logproto.ChunkRef) []*logproto.GroupedChunkRefs {
t.Helper()
grouped := make([]*logproto.GroupedChunkRefs, 0, len(chunkRefs))
Expand Down Expand Up @@ -155,8 +163,7 @@ func TestBloomGateway_FilterChunkRefs(t *testing.T) {
require.NoError(t, err)
})

ts, _ := time.Parse("2006-01-02 15:04", "2023-10-03 10:00")
now := model.TimeFromUnix(ts.Unix())
now := mktime("2023-10-03 10:00")

chunkRefs := []*logproto.ChunkRef{
{Fingerprint: 3000, UserID: tenantID, From: now.Add(-24 * time.Hour), Through: now.Add(-23 * time.Hour), Checksum: 1},
Expand Down Expand Up @@ -194,8 +201,7 @@ func TestBloomGateway_FilterChunkRefs(t *testing.T) {
gw, err := New(cfg, schemaCfg, storageCfg, ss, cm, logger, reg)
require.NoError(t, err)

ts, _ := time.Parse("2006-01-02 15:04", "2023-10-03 10:00")
now := model.TimeFromUnix(ts.Unix())
now := mktime("2023-10-03 10:00")

chunkRefs := []*logproto.ChunkRef{
{Fingerprint: 1000, UserID: tenantID, From: now.Add(-22 * time.Hour), Through: now.Add(-21 * time.Hour), Checksum: 1},
Expand Down Expand Up @@ -228,8 +234,7 @@ func TestBloomGateway_FilterChunkRefs(t *testing.T) {
require.NoError(t, err)
})

ts, _ := time.Parse("2006-01-02 15:04", "2023-10-03 10:00")
now := model.TimeFromUnix(ts.Unix())
now := mktime("2023-10-03 10:00")

tenants := []string{"tenant-a", "tenant-b", "tenant-c"}
for idx, tenantID := range tenants {
Expand Down Expand Up @@ -262,8 +267,7 @@ func TestBloomGateway_FilterChunkRefs(t *testing.T) {
gw, err := New(cfg, schemaCfg, storageCfg, ss, cm, logger, reg)
require.NoError(t, err)

ts, _ := time.Parse("2006-01-02 15:04", "2023-10-03 10:00")
now := model.TimeFromUnix(ts.Unix())
now := mktime("2023-10-03 10:00")

// replace store implementation and re-initialize workers and sub-services
bqs, data := createBlockQueriers(t, 5, now.Add(-8*time.Hour), now, 0, 1024)
Expand Down

0 comments on commit 2c1586c

Please sign in to comment.