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
This commit is contained in:
Marcus Efraimsson 2022-12-09 08:11:56 +01:00 committed by GitHub
parent 896cb9ddce
commit 2db8ed9441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 31 deletions

View File

@ -31,6 +31,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

View File

@ -25,7 +25,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,

View File

@ -20,7 +20,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,
@ -137,7 +139,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,

View File

@ -34,7 +34,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,
@ -392,7 +394,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,
@ -549,7 +553,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,
@ -664,7 +670,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,
@ -824,7 +832,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,
@ -1802,7 +1812,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,
@ -1865,7 +1877,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,
@ -2064,7 +2078,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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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"
}
}`

View File

@ -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,

View File

@ -29,7 +29,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)
@ -114,7 +118,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,

View File

@ -30,7 +30,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,
})

View File

@ -345,6 +345,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

View File

@ -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,