diff --git a/promql/promqltest/test.go b/promql/promqltest/test.go index f3a578a9ab..cc02a5b40f 100644 --- a/promql/promqltest/test.go +++ b/promql/promqltest/test.go @@ -39,7 +39,6 @@ import ( "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser/posrange" "github.com/prometheus/prometheus/storage" - "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/util/almost" "github.com/prometheus/prometheus/util/annotations" "github.com/prometheus/prometheus/util/convertnhcb" @@ -254,11 +253,14 @@ func newTest(t testing.TB, input string, testingMode bool, newStorage func(testi return test, err } +// testStorageOptions holds additional tsdb.Options applied by newTestStorage. +// It is populated via init() in test files so that options only take effect +// when the promqltest package itself is under test, not when callers such as +// promql_test.go invoke RunBuiltinTests. +var testStorageOptions []teststorage.Option + func newTestStorage(t testing.TB) storage.Storage { - return teststorage.New(t, func(opts *tsdb.Options) { - opts.EnableSTStorage = true - opts.EnableXOR2Encoding = true - }) + return teststorage.New(t, testStorageOptions...) } //go:embed testdata diff --git a/promql/promqltest/test_test.go b/promql/promqltest/test_test.go index ef0203b993..7634eabde0 100644 --- a/promql/promqltest/test_test.go +++ b/promql/promqltest/test_test.go @@ -24,9 +24,20 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql/parser" + "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb/chunkenc" + "github.com/prometheus/prometheus/util/teststorage" ) +func init() { + testStorageOptions = []teststorage.Option{ + func(opts *tsdb.Options) { + opts.EnableSTStorage = true + opts.EnableXOR2Encoding = true + }, + } +} + func TestLazyLoader_WithSamplesTill(t *testing.T) { type testCase struct { ts time.Time