@@ -19,16 +19,14 @@ import (
1919 "github.com/prometheus/prometheus/storage"
2020 v1 "github.com/prometheus/prometheus/web/api/v1"
2121 "github.com/stretchr/testify/require"
22- "github.com/thanos-community/promql-engine/engine"
23- "github.com/thanos-community/promql-engine/logicalplan"
2422 "github.com/weaveworks/common/httpgrpc"
2523 "github.com/weaveworks/common/user"
2624
2725 "github.com/cortexproject/cortex/pkg/util/validation"
2826)
2927
3028func TestApiStatusCodes (t * testing.T ) {
31- //parallel testing causes data race
29+ t . Parallel ()
3230
3331 for ix , tc := range []struct {
3432 err error
@@ -104,41 +102,31 @@ func TestApiStatusCodes(t *testing.T) {
104102 expectedCode : 422 ,
105103 },
106104 } {
107- for _ , thanosEngine := range []bool {false , true } {
108- for k , q := range map [string ]storage.SampleAndChunkQueryable {
109- "error from queryable" : errorTestQueryable {err : tc .err },
110- "error from querier" : errorTestQueryable {q : errorTestQuerier {err : tc .err }},
111- "error from seriesset" : errorTestQueryable {q : errorTestQuerier {s : errorTestSeriesSet {err : tc .err }}},
112- } {
113- t .Run (fmt .Sprintf ("%s/%d" , k , ix ), func (t * testing.T ) {
114- opts := promql.EngineOpts {
115- Logger : log .NewNopLogger (),
116- Reg : nil ,
117- ActiveQueryTracker : nil ,
118- MaxSamples : 100 ,
119- Timeout : 5 * time .Second ,
120- }
121- var queryEngine v1.QueryEngine
122- if thanosEngine {
123- queryEngine = engine .New (engine.Opts {
124- EngineOpts : opts ,
125- LogicalOptimizers : logicalplan .AllOptimizers ,
126- })
127- } else {
128- queryEngine = promql .NewEngine (opts )
129- }
130- r := createPrometheusAPI (NewErrorTranslateSampleAndChunkQueryable (q ), queryEngine )
131- rec := httptest .NewRecorder ()
132-
133- req := httptest .NewRequest ("GET" , "/api/v1/query?query=up" , nil )
134- req = req .WithContext (user .InjectOrgID (context .Background (), "test org" ))
135-
136- r .ServeHTTP (rec , req )
137-
138- require .Equal (t , tc .expectedCode , rec .Code )
139- require .Contains (t , rec .Body .String (), tc .expectedString )
140- })
141- }
105+ for k , q := range map [string ]storage.SampleAndChunkQueryable {
106+ "error from queryable" : errorTestQueryable {err : tc .err },
107+ "error from querier" : errorTestQueryable {q : errorTestQuerier {err : tc .err }},
108+ "error from seriesset" : errorTestQueryable {q : errorTestQuerier {s : errorTestSeriesSet {err : tc .err }}},
109+ } {
110+ t .Run (fmt .Sprintf ("%s/%d" , k , ix ), func (t * testing.T ) {
111+ opts := promql.EngineOpts {
112+ Logger : log .NewNopLogger (),
113+ Reg : nil ,
114+ ActiveQueryTracker : nil ,
115+ MaxSamples : 100 ,
116+ Timeout : 5 * time .Second ,
117+ }
118+ queryEngine := promql .NewEngine (opts )
119+ r := createPrometheusAPI (NewErrorTranslateSampleAndChunkQueryable (q ), queryEngine )
120+ rec := httptest .NewRecorder ()
121+
122+ req := httptest .NewRequest ("GET" , "/api/v1/query?query=up" , nil )
123+ req = req .WithContext (user .InjectOrgID (context .Background (), "test org" ))
124+
125+ r .ServeHTTP (rec , req )
126+
127+ require .Equal (t , tc .expectedCode , rec .Code )
128+ require .Contains (t , rec .Body .String (), tc .expectedString )
129+ })
142130 }
143131 }
144132}
0 commit comments