@@ -32,6 +32,7 @@ import (
32
32
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb"
33
33
"github.com/cortexproject/cortex/pkg/util"
34
34
"github.com/cortexproject/cortex/pkg/util/services"
35
+ "github.com/cortexproject/cortex/pkg/util/validation"
35
36
)
36
37
37
38
func TestBlocksStoreQuerier_Select (t * testing.T ) {
@@ -67,18 +68,18 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
67
68
storeSetResponses []interface {}
68
69
limits BlocksStoreLimits
69
70
expectedSeries []seriesResult
70
- expectedErr string
71
+ expectedErr error
71
72
expectedMetrics string
72
73
}{
73
74
"no block in the storage matching the query time range" : {
74
75
finderResult : nil ,
75
76
limits : & blocksStoreLimitsMock {},
76
- expectedErr : "" ,
77
+ expectedErr : nil ,
77
78
},
78
79
"error while finding blocks matching the query time range" : {
79
80
finderErr : errors .New ("unable to find blocks" ),
80
81
limits : & blocksStoreLimitsMock {},
81
- expectedErr : "unable to find blocks" ,
82
+ expectedErr : errors . New ( "unable to find blocks" ) ,
82
83
},
83
84
"error while getting clients to query the store-gateway" : {
84
85
finderResult : bucketindex.Blocks {
@@ -89,7 +90,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
89
90
errors .New ("no client found" ),
90
91
},
91
92
limits : & blocksStoreLimitsMock {},
92
- expectedErr : "no client found" ,
93
+ expectedErr : errors . New ( "no client found" ) ,
93
94
},
94
95
"a single store-gateway instance holds the required blocks (single returned series)" : {
95
96
finderResult : bucketindex.Blocks {
@@ -290,7 +291,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
290
291
errors .New ("no store-gateway remaining after exclude" ),
291
292
},
292
293
limits : & blocksStoreLimitsMock {},
293
- expectedErr : fmt .Sprintf ("consistency check failed because some blocks were not queried: %s" , block2 .String ()),
294
+ expectedErr : fmt .Errorf ("consistency check failed because some blocks were not queried: %s" , block2 .String ()),
294
295
},
295
296
"multiple store-gateway instances have some missing blocks (consistency check failed)" : {
296
297
finderResult : bucketindex.Blocks {
@@ -315,7 +316,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
315
316
errors .New ("no store-gateway remaining after exclude" ),
316
317
},
317
318
limits : & blocksStoreLimitsMock {},
318
- expectedErr : fmt .Sprintf ("consistency check failed because some blocks were not queried: %s %s" , block3 .String (), block4 .String ()),
319
+ expectedErr : fmt .Errorf ("consistency check failed because some blocks were not queried: %s %s" , block3 .String (), block4 .String ()),
319
320
},
320
321
"multiple store-gateway instances have some missing blocks but queried from a replica during subsequent attempts" : {
321
322
finderResult : bucketindex.Blocks {
@@ -435,7 +436,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
435
436
},
436
437
},
437
438
limits : & blocksStoreLimitsMock {maxChunksPerQuery : 1 },
438
- expectedErr : fmt .Sprintf (errMaxChunksPerQueryLimit , fmt .Sprintf ("{__name__=%q}" , metricName ), 1 ),
439
+ expectedErr : validation . LimitError ( fmt .Sprintf (errMaxChunksPerQueryLimit , fmt .Sprintf ("{__name__=%q}" , metricName ), 1 ) ),
439
440
},
440
441
"max chunks per query limit hit while fetching chunks during subsequent attempts" : {
441
442
finderResult : bucketindex.Blocks {
@@ -472,7 +473,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
472
473
},
473
474
},
474
475
limits : & blocksStoreLimitsMock {maxChunksPerQuery : 3 },
475
- expectedErr : fmt .Sprintf (errMaxChunksPerQueryLimit , fmt .Sprintf ("{__name__=%q}" , metricName ), 3 ),
476
+ expectedErr : validation . LimitError ( fmt .Sprintf (errMaxChunksPerQueryLimit , fmt .Sprintf ("{__name__=%q}" , metricName ), 3 ) ),
476
477
},
477
478
}
478
479
@@ -502,8 +503,9 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
502
503
}
503
504
504
505
set := q .Select (true , nil , matchers ... )
505
- if testData .expectedErr != "" {
506
- assert .EqualError (t , set .Err (), testData .expectedErr )
506
+ if testData .expectedErr != nil {
507
+ assert .EqualError (t , set .Err (), testData .expectedErr .Error ())
508
+ assert .IsType (t , set .Err (), testData .expectedErr )
507
509
assert .False (t , set .Next ())
508
510
assert .Nil (t , set .Warnings ())
509
511
return
0 commit comments