diff --git a/pkg/storage/unified/apistore/watcher_test.go b/pkg/storage/unified/apistore/watcher_test.go index c68415bca97..91a251b04d0 100644 --- a/pkg/storage/unified/apistore/watcher_test.go +++ b/pkg/storage/unified/apistore/watcher_test.go @@ -40,6 +40,7 @@ import ( "github.com/grafana/grafana/pkg/storage/unified/resourcepb" "github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" + "github.com/grafana/grafana/pkg/tests" "github.com/grafana/grafana/pkg/tests/testsuite" ) @@ -134,9 +135,7 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte _, err = server.IsHealthy(ctx, &resourcepb.HealthCheckRequest{}) require.NoError(t, err) case StorageTypeUnified: - if testing.Short() { - t.Skip("skipping integration test") - } + tests.SkipIntegrationTestInShortMode(t) dbstore := infraDB.InitTestDB(t) cfg := setting.NewCfg() @@ -190,7 +189,7 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte return ctx, store, destroyFunc, nil } -func TestWatch(t *testing.T) { +func TestIntegrationWatch(t *testing.T) { for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} { t.Run(string(s), func(t *testing.T) { ctx, store, destroyFunc, err := testSetup(t, withStorageType(s)) diff --git a/pkg/storage/unified/search/bleve_integration_test.go b/pkg/storage/unified/search/bleve_integration_test.go index 6c28d560087..f76f89255e0 100644 --- a/pkg/storage/unified/search/bleve_integration_test.go +++ b/pkg/storage/unified/search/bleve_integration_test.go @@ -13,10 +13,6 @@ import ( ) func TestBleveSearchBackend(t *testing.T) { - if testing.Short() { - t.Skip("skipping integration test") - } - // Run the search backend test suite unitest.RunSearchBackendTest(t, func(ctx context.Context) resource.SearchBackend { tempDir := t.TempDir() diff --git a/pkg/storage/unified/sql/test/benchmark_test.go b/pkg/storage/unified/sql/test/benchmark_test.go index d937abb70ab..88f9ed2c955 100644 --- a/pkg/storage/unified/sql/test/benchmark_test.go +++ b/pkg/storage/unified/sql/test/benchmark_test.go @@ -17,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" test "github.com/grafana/grafana/pkg/storage/unified/testing" + "github.com/grafana/grafana/pkg/tests" ) func newTestBackend(b testing.TB) resource.StorageBackend { @@ -38,9 +39,7 @@ func newTestBackend(b testing.TB) resource.StorageBackend { } func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) { - if testing.Short() { - t.Skip("skipping integration test in short mode") - } + tests.SkipIntegrationTestInShortMode(t) opts := test.DefaultBenchmarkOptions() if db.IsTestDbSQLite() { opts.Concurrency = 1 // to avoid SQLite database is locked error @@ -49,9 +48,7 @@ func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) { } func TestIntegrationBenchmarkResourceServer(t *testing.T) { - if testing.Short() { - t.Skip("skipping integration test in short mode") - } + tests.SkipIntegrationTestInShortMode(t) ctx := context.Background() opts := &test.BenchmarkOptions{ diff --git a/pkg/storage/unified/sql/test/integration_test.go b/pkg/storage/unified/sql/test/integration_test.go index 99ff031aab1..e33af48713f 100644 --- a/pkg/storage/unified/sql/test/integration_test.go +++ b/pkg/storage/unified/sql/test/integration_test.go @@ -26,6 +26,7 @@ import ( "github.com/grafana/grafana/pkg/storage/unified/sql" "github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl" unitest "github.com/grafana/grafana/pkg/storage/unified/testing" + "github.com/grafana/grafana/pkg/tests" "github.com/grafana/grafana/pkg/tests/testsuite" "github.com/grafana/grafana/pkg/util/testutil" ) @@ -95,9 +96,7 @@ func TestIntegrationSQLStorageBackend(t *testing.T) { } func TestIntegrationSearchAndStorage(t *testing.T) { - if testing.Short() { - t.Skip("skipping integration test in short mode") - } + tests.SkipIntegrationTestInShortMode(t) ctx := context.Background() diff --git a/pkg/storage/unified/testing/kv.go b/pkg/storage/unified/testing/kv.go index 5c205697e69..0c3b745fdf0 100644 --- a/pkg/storage/unified/testing/kv.go +++ b/pkg/storage/unified/testing/kv.go @@ -43,10 +43,6 @@ func GenerateRandomKVPrefix() string { // RunKVTest runs the KV test suite func RunKVTest(t *testing.T, newKV NewKVFunc, opts *KVTestOptions) { - if testing.Short() { - t.Skip("skipping integration test") - } - if opts == nil { opts = &KVTestOptions{} } diff --git a/pkg/storage/unified/testing/search_backend.go b/pkg/storage/unified/testing/search_backend.go index 505e1b1a43d..57d887682c6 100644 --- a/pkg/storage/unified/testing/search_backend.go +++ b/pkg/storage/unified/testing/search_backend.go @@ -24,10 +24,6 @@ type NewSearchBackendFunc func(ctx context.Context) resource.SearchBackend // RunSearchBackendTest runs the search backend test suite func RunSearchBackendTest(t *testing.T, newBackend NewSearchBackendFunc, opts *TestOptions) { - if testing.Short() { - t.Skip("skipping integration test") - } - if opts == nil { opts = &TestOptions{} } diff --git a/pkg/tests/utils.go b/pkg/tests/utils.go index f81683c80f4..4ea428df9f7 100644 --- a/pkg/tests/utils.go +++ b/pkg/tests/utils.go @@ -5,10 +5,13 @@ import ( "crypto/tls" "net/url" "os" + "strings" "testing" "github.com/go-openapi/strfmt" goapi "github.com/grafana/grafana-openapi-client-go/client" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" @@ -19,9 +22,18 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user/userimpl" "github.com/grafana/grafana/pkg/setting" - "github.com/stretchr/testify/require" ) +func SkipIntegrationTestInShortMode(t testing.TB) { + t.Helper() + if !strings.HasPrefix(t.Name(), "TestIntegration") { + t.Fatal("test is not an integration test") + } + if testing.Short() { + t.Skip("skipping integration test in short mode") + } +} + func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 { t.Helper()