diff --git a/pkg/infra/db/db.go b/pkg/infra/db/db.go index ad2d58f3242..5e8e6a0355d 100644 --- a/pkg/infra/db/db.go +++ b/pkg/infra/db/db.go @@ -5,6 +5,7 @@ import ( "os" "xorm.io/core" + "xorm.io/xorm" "github.com/grafana/grafana/pkg/services/sqlstore" @@ -53,6 +54,7 @@ type InitTestDBOpt = sqlstore.InitTestDBOpt var SetupTestDB = sqlstore.SetupTestDB var CleanupTestDB = sqlstore.CleanupTestDB var ProvideService = sqlstore.ProvideService +var SkipTestsOnSpanner = sqlstore.SkipTestsOnSpanner func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *sqlstore.SQLStore { db, _ := InitTestDBWithCfg(t, opts...) diff --git a/pkg/services/ngalert/store/alertmanager_test.go b/pkg/services/ngalert/store/alertmanager_test.go index 4f27e2b6e83..8f8d9414ebb 100644 --- a/pkg/services/ngalert/store/alertmanager_test.go +++ b/pkg/services/ngalert/store/alertmanager_test.go @@ -17,7 +17,7 @@ import ( ) func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func TestIntegrationAlertmanagerStore(t *testing.T) { diff --git a/pkg/services/sqlstore/sqlstore.go b/pkg/services/sqlstore/sqlstore.go index 10dcf1d0c14..a8a6636675c 100644 --- a/pkg/services/sqlstore/sqlstore.go +++ b/pkg/services/sqlstore/sqlstore.go @@ -414,6 +414,7 @@ var testSQLStoreSetup = false var testSQLStore *SQLStore var testSQLStoreMutex sync.Mutex var testSQLStoreCleanup []func() +var testSQLStoreSkipTestsOnBackend string // When not empty and matches DB type, test is skipped. // InitTestDBOpt contains options for InitTestDB. type InitTestDBOpt struct { @@ -458,6 +459,12 @@ func SetupTestDB() { testSQLStoreSetup = true } +func SkipTestsOnSpanner() { + testSQLStoreMutex.Lock() + defer testSQLStoreMutex.Unlock() + testSQLStoreSkipTestsOnBackend = "spanner" +} + func CleanupTestDB() { testSQLStoreMutex.Lock() defer testSQLStoreMutex.Unlock() @@ -542,6 +549,10 @@ func TestMain(m *testing.M) { if testSQLStore == nil { dbType := sqlutil.GetTestDBType() + if testSQLStoreSkipTestsOnBackend != "" && testSQLStoreSkipTestsOnBackend == dbType { + t.Skipf("test skipped when using DB type %s", testSQLStoreSkipTestsOnBackend) + } + // set test db config cfg := setting.NewCfg() // nolint:staticcheck diff --git a/pkg/services/sqlstore/sqlutil/sqlutil.go b/pkg/services/sqlstore/sqlutil/sqlutil.go index d80104c55bd..2950aeabf76 100644 --- a/pkg/services/sqlstore/sqlutil/sqlutil.go +++ b/pkg/services/sqlstore/sqlutil/sqlutil.go @@ -17,6 +17,7 @@ type ITestDB interface { Logf(format string, args ...any) Log(args ...any) Cleanup(func()) + Skipf(format string, args ...any) } type TestDB struct { diff --git a/pkg/tests/api/alerting/api_testing_test.go b/pkg/tests/api/alerting/api_testing_test.go index dd04d3b8301..ccba1810f65 100644 --- a/pkg/tests/api/alerting/api_testing_test.go +++ b/pkg/tests/api/alerting/api_testing_test.go @@ -33,7 +33,7 @@ const ( ) func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func TestGrafanaRuleConfig(t *testing.T) { diff --git a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go index 34475e9d4c3..d3c69f9771d 100644 --- a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go +++ b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go @@ -53,7 +53,7 @@ import ( var testData embed.FS func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func getTestHelper(t *testing.T) *apis.K8sTestHelper { diff --git a/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go b/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go index 29b941106ad..93ea886c5ff 100644 --- a/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go +++ b/pkg/tests/apis/alerting/notifications/routingtree/routing_tree_test.go @@ -38,7 +38,7 @@ import ( ) func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func getTestHelper(t *testing.T) *apis.K8sTestHelper { diff --git a/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go b/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go index 3e6ef4dc14a..8dbaf88f4f2 100644 --- a/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go +++ b/pkg/tests/apis/alerting/notifications/templategroup/templates_group_test.go @@ -33,7 +33,7 @@ import ( ) func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func getTestHelper(t *testing.T) *apis.K8sTestHelper { diff --git a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go index ac60110face..42b416d978d 100644 --- a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go +++ b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go @@ -43,7 +43,7 @@ import ( var testData embed.FS func TestMain(m *testing.M) { - testsuite.Run(m) + testsuite.RunButSkipOnSpanner(m) } func getTestHelper(t *testing.T) *apis.K8sTestHelper { diff --git a/pkg/tests/testsuite/testsuite.go b/pkg/tests/testsuite/testsuite.go index 87ce57eaa15..80378e2530b 100644 --- a/pkg/tests/testsuite/testsuite.go +++ b/pkg/tests/testsuite/testsuite.go @@ -13,3 +13,8 @@ func Run(m *testing.M) { db.CleanupTestDB() os.Exit(code) } + +func RunButSkipOnSpanner(m *testing.M) { + db.SkipTestsOnSpanner() + Run(m) +}