[v9.3.x] Chore: All tests under pkg/tests should be integration tests (#60071)
Chore: All tests under pkg/tests should be integration tests (#59521)
* Chore: All tests under pkg/tests should be integrationtests
* run alerting integration tests only for sqlite
(cherry picked from commit 2db8ed9441)
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
co-authored by
Marcus Efraimsson
parent
ea2a7a4068
commit
5fa57d2c1e
@@ -30,6 +30,14 @@ var InitTestDBwithCfg = sqlstore.InitTestDBWithCfg
|
||||
var ProvideService = sqlstore.ProvideService
|
||||
var NewSqlBuilder = sqlstore.NewSqlBuilder
|
||||
|
||||
func IsTestDbSQLite() bool {
|
||||
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); !present || db == "sqlite" {
|
||||
return true
|
||||
}
|
||||
|
||||
return !IsTestDbMySQL() && !IsTestDbPostgres()
|
||||
}
|
||||
|
||||
func IsTestDbMySQL() bool {
|
||||
if db, present := os.LookupEnv("GRAFANA_TEST_DB"); present {
|
||||
return db == migrator.MySQL
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
)
|
||||
|
||||
func TestAdminConfiguration_SendingToExternalAlertmanagers(t *testing.T) {
|
||||
func TestIntegrationAdminConfiguration_SendingToExternalAlertmanagers(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
const disableOrgID int64 = 3
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
|
||||
@@ -17,7 +17,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAlertmanagerConfigurationIsTransactional(t *testing.T) {
|
||||
func TestIntegrationAlertmanagerConfigurationIsTransactional(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
@@ -129,7 +131,9 @@ func TestAlertmanagerConfigurationIsTransactional(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertmanagerConfigurationPersistSecrets(t *testing.T) {
|
||||
func TestIntegrationAlertmanagerConfigurationPersistSecrets(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
|
||||
@@ -31,7 +31,9 @@ type Response struct {
|
||||
TraceID string `json:"traceID"`
|
||||
}
|
||||
|
||||
func TestAMConfigAccess(t *testing.T) {
|
||||
func TestIntegrationAMConfigAccess(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
@@ -389,7 +391,9 @@ func TestAMConfigAccess(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAlertAndGroupsQuery(t *testing.T) {
|
||||
func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
@@ -546,7 +550,9 @@ func TestAlertAndGroupsQuery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRulerAccess(t *testing.T) {
|
||||
func TestIntegrationRulerAccess(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -661,7 +667,9 @@ func TestRulerAccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteFolderWithRules(t *testing.T) {
|
||||
func TestIntegrationDeleteFolderWithRules(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -821,7 +829,9 @@ func TestDeleteFolderWithRules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertRuleCRUD(t *testing.T) {
|
||||
func TestIntegrationAlertRuleCRUD(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -1799,7 +1809,9 @@ func TestAlertRuleCRUD(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertmanagerStatus(t *testing.T) {
|
||||
func TestIntegrationAlertmanagerStatus(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -1862,7 +1874,9 @@ func TestAlertmanagerStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuota(t *testing.T) {
|
||||
func TestIntegrationQuota(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -2061,7 +2075,9 @@ func TestQuota(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestEval(t *testing.T) {
|
||||
func TestIntegrationEval(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
|
||||
@@ -15,7 +15,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
)
|
||||
|
||||
func TestAvailableChannels(t *testing.T) {
|
||||
func TestIntegrationAvailableChannels(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
|
||||
@@ -31,7 +31,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
)
|
||||
|
||||
func TestTestReceivers(t *testing.T) {
|
||||
func TestIntegrationTestReceivers(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
t.Run("assert no receivers returns 400 Bad Request", func(t *testing.T) {
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
@@ -423,7 +425,9 @@ func TestTestReceivers(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTestReceiversAlertCustomization(t *testing.T) {
|
||||
func TestIntegrationTestReceiversAlertCustomization(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
t.Run("assert custom annotations and labels are sent", func(t *testing.T) {
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
@@ -693,7 +697,9 @@ func TestTestReceiversAlertCustomization(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestNotificationChannels(t *testing.T) {
|
||||
func TestIntegrationNotificationChannels(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
|
||||
@@ -24,7 +24,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
)
|
||||
|
||||
func TestPrometheusRules(t *testing.T) {
|
||||
func TestIntegrationPrometheusRules(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
@@ -319,7 +321,9 @@ func TestPrometheusRules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrometheusRulesFilterByDashboard(t *testing.T) {
|
||||
func TestIntegrationPrometheusRulesFilterByDashboard(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
EnableFeatureToggles: []string{"ngalert"},
|
||||
DisableAnonymous: true,
|
||||
@@ -612,7 +616,9 @@ func TestPrometheusRulesFilterByDashboard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrometheusRulesPermissions(t *testing.T) {
|
||||
func TestIntegrationPrometheusRulesPermissions(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
|
||||
@@ -13,7 +13,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestProvisioning(t *testing.T) {
|
||||
func TestIntegrationProvisioning(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
EnableUnifiedAlerting: true,
|
||||
@@ -59,7 +61,7 @@ func TestProvisioning(t *testing.T) {
|
||||
"name": "test-receiver",
|
||||
"type": "slack",
|
||||
"settings": {
|
||||
"recipient": "value_recipient",
|
||||
"recipient": "value_recipient",
|
||||
"token": "value_token"
|
||||
}
|
||||
}`
|
||||
@@ -157,7 +159,7 @@ func TestProvisioning(t *testing.T) {
|
||||
"name": "my-contact-point",
|
||||
"type": "slack",
|
||||
"settings": {
|
||||
"recipient": "value_recipient",
|
||||
"recipient": "value_recipient",
|
||||
"token": "value_token"
|
||||
}
|
||||
}`
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func TestAlertRulePermissions(t *testing.T) {
|
||||
func TestIntegrationAlertRulePermissions(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -311,7 +313,9 @@ func createRule(t *testing.T, client apiClient, folder string) {
|
||||
require.JSONEq(t, `{"message":"rule group updated successfully"}`, body)
|
||||
}
|
||||
|
||||
func TestAlertRuleConflictingTitle(t *testing.T) {
|
||||
func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -382,7 +386,9 @@ func TestAlertRuleConflictingTitle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRulerRulesFilterByDashboard(t *testing.T) {
|
||||
func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
EnableFeatureToggles: []string{"ngalert"},
|
||||
DisableAnonymous: true,
|
||||
@@ -719,7 +725,9 @@ func TestRulerRulesFilterByDashboard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuleGroupSequence(t *testing.T) {
|
||||
func TestIntegrationRuleGroupSequence(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
@@ -815,7 +823,9 @@ func TestRuleGroupSequence(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRuleUpdate(t *testing.T) {
|
||||
func TestIntegrationRuleUpdate(t *testing.T) {
|
||||
testinfra.SQLiteIntegrationTest(t)
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableLegacyAlerting: true,
|
||||
|
||||
@@ -26,7 +26,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
)
|
||||
|
||||
func TestDashboardQuota(t *testing.T) {
|
||||
func TestIntegrationDashboardQuota(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
// enable quota and set low dashboard quota
|
||||
// Setup Grafana and its Database
|
||||
dashboardQuota := int64(1)
|
||||
@@ -105,7 +109,11 @@ func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserComma
|
||||
return u.ID
|
||||
}
|
||||
|
||||
func TestUpdatingProvisionionedDashboards(t *testing.T) {
|
||||
func TestIntegrationUpdatingProvisionionedDashboards(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableAnonymous: true,
|
||||
|
||||
@@ -27,7 +27,11 @@ const (
|
||||
|
||||
var updateSnapshotFlag = false
|
||||
|
||||
func TestPlugins(t *testing.T) {
|
||||
func TestIntegrationPlugins(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
PluginAdminEnabled: true,
|
||||
})
|
||||
|
||||
@@ -335,6 +335,14 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
|
||||
return tmpDir, cfgPath
|
||||
}
|
||||
|
||||
func SQLiteIntegrationTest(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
if testing.Short() || !db.IsTestDbSQLite() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
}
|
||||
|
||||
type GrafanaOpts struct {
|
||||
EnableCSP bool
|
||||
EnableFeatureToggles []string
|
||||
|
||||
@@ -12,8 +12,12 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestIndexView tests the Grafana index view.
|
||||
func TestIndexView(t *testing.T) {
|
||||
// TestIntegrationIndexView tests the Grafana index view.
|
||||
func TestIntegrationIndexView(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
t.Run("CSP enabled", func(t *testing.T) {
|
||||
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
EnableCSP: true,
|
||||
|
||||
Reference in New Issue
Block a user