@@ -10,6 +10,7 @@ import (
1010 "testing"
1111 "time"
1212
13+ "github.com/dustin/go-humanize"
1314 "github.com/go-kit/log"
1415 "github.com/gorilla/mux"
1516 "github.com/grafana/dskit/concurrency"
@@ -140,10 +141,11 @@ func TestHandlers_CreateIndexHandler(t *testing.T) {
140141}
141142
142143func Test_filterAndGroupBlocks (t * testing.T ) {
143- block1 := & bucketindex.Block {ID : ulid .MustNew (1 , nil ), MinTime : model .Now ().Add (- 2 * time .Hour ), MaxTime : model .Now ().Add (- 1 * time .Hour )}
144- block2 := & bucketindex.Block {ID : ulid .MustNew (2 , nil ), MinTime : model .Now ().Add (- 4 * time .Hour ), MaxTime : model .Now ().Add (- 3 * time .Hour )}
145- block3 := & bucketindex.Block {ID : ulid .MustNew (3 , nil ), MinTime : model .Now ().Add (- 4 * time .Hour + time .Minute ), MaxTime : model .Now ().Add (- 3 * time .Hour )}
146- block4 := & bucketindex.Block {ID : ulid .MustNew (4 , nil ), MinTime : model .Now ().Add (- 12 * time .Hour ), MaxTime : model .Now ().Add (- 10 * time .Hour )}
144+ now := model .TimeFromUnixNano (time .Date (2025 , 10 , 16 , 16 , 0 , 0 , 0 , time .UTC ).UnixNano ())
145+ block1 := & bucketindex.Block {ID : ulid .MustNew (1 , nil ), MinTime : now .Add (- 2 * time .Hour ), MaxTime : now .Add (- 1 * time .Hour )}
146+ block2 := & bucketindex.Block {ID : ulid .MustNew (2 , nil ), MinTime : now .Add (- 4 * time .Hour ), MaxTime : now .Add (- 3 * time .Hour )}
147+ block3 := & bucketindex.Block {ID : ulid .MustNew (3 , nil ), MinTime : now .Add (- 4 * time .Hour + time .Minute ), MaxTime : now .Add (- 3 * time .Hour )}
148+ block4 := & bucketindex.Block {ID : ulid .MustNew (4 , nil ), MinTime : now .Add (- 12 * time .Hour ), MaxTime : now .Add (- 10 * time .Hour )}
147149 h := & Handlers {MaxBlockDuration : time .Hour }
148150
149151 type args struct {
@@ -177,8 +179,8 @@ func Test_filterAndGroupBlocks(t *testing.T) {
177179 BlockDeletionMarks : bucketindex.BlockDeletionMarks {& bucketindex.BlockDeletionMark {ID : block1 .ID }},
178180 },
179181 query : & blockQuery {
180- parsedFrom : time . Now ().Add (- 6 * time .Hour ),
181- parsedTo : time . Now (),
182+ parsedFrom : now . Time ().Add (- 6 * time .Hour ),
183+ parsedTo : now . Time (),
182184 }},
183185 want : & blockListResult {
184186 // block 1 is not included because it is marked as deleted
@@ -205,7 +207,7 @@ func Test_filterAndGroupBlocks(t *testing.T) {
205207 UploadedAt : time .UnixMilli (0 ).UTC ().Format (time .RFC3339 ),
206208 },
207209 },
208- MinTimeAge : "4 hours ago" ,
210+ MinTimeAge : humanize . RelTime ( block2 . MinTime . Time (), now . Time (), " ago", "" ) ,
209211 MaxBlockDurationMinutes : 60 ,
210212 },
211213 },
@@ -216,7 +218,7 @@ func Test_filterAndGroupBlocks(t *testing.T) {
216218 }
217219 for _ , tt := range tests {
218220 t .Run (tt .name , func (t * testing.T ) {
219- assert .Equalf (t , tt .want , h .filterAndGroupBlocks (tt .args .index , tt .args .query ), "filterAndGroupBlocks(%v, %v)" , tt .args .index , tt .args .query )
221+ assert .Equalf (t , tt .want , h .filterAndGroupBlocks (tt .args .index , tt .args .query , now . Time () ), "filterAndGroupBlocks(%v, %v)" , tt .args .index , tt .args .query )
220222 })
221223 }
222224}
0 commit comments