Replace remaining calls to testing.Short where possible. (#110765)

* Replace remaining calls to testing.Short where possible.
* Update style guide.
* Revert change in TestAlertmanager_ExtraDedupStage, as it doesn't work.
* Make TestAlertRulePostExport into integration test.
This commit is contained in:
Peter Štibraný
2025-09-09 08:16:12 +00:00
committed by GitHub
parent ffcc0e8de0
commit c32650e9d8
16 changed files with 76 additions and 88 deletions
@@ -4,11 +4,13 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/commandstest"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/util/testutil"
)
func TestValidateInput(t *testing.T) {
@@ -81,6 +83,43 @@ func TestValidateInput(t *testing.T) {
}
}
func TestIntegrationPluginRepoConfig(t *testing.T) {
testutil.SkipIntegrationTestInShortMode(t)
t.Run("Should use config parameter if it is set", func(t *testing.T) {
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
GrafanaComAPIURL: "https://grafana-dev.com",
GrafanaComSSOAPIToken: "token3",
})
c, err := commandstest.NewCliContext(map[string]string{
"config": cfgPath,
"homepath": grafDir,
})
require.NoError(t, err)
repoURL := c.PluginRepoURL()
require.Equal(t, "https://grafana-dev.com/plugins", repoURL)
token := c.GcomToken()
require.Equal(t, "token3", token)
})
t.Run("Should use config overrides parameter if it is set alongside config parameter", func(t *testing.T) {
// GrafanaComApiUrl is set to the default path https://grafana.com/api
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
// overriding the GrafanaComApiUrl to https://grafana-dev.com
c, err := commandstest.NewCliContext(map[string]string{
"config": cfgPath,
"homepath": grafDir,
"configOverrides": "cfg:grafana_com.api_url=https://grafana-dev.com",
})
require.NoError(t, err)
repoURL := c.PluginRepoURL()
require.Equal(t, "https://grafana-dev.com/plugins", repoURL)
})
}
func TestValidatePluginRepoConfig(t *testing.T) {
t.Run("Should use provided repo parameter for installation", func(t *testing.T) {
c, err := commandstest.NewCliContext(map[string]string{
@@ -100,44 +139,4 @@ func TestValidatePluginRepoConfig(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "https://example.com", c.PluginRepoURL())
})
t.Run("Should use config parameter if it is set", func(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
GrafanaComAPIURL: "https://grafana-dev.com",
GrafanaComSSOAPIToken: "token3",
})
c, err := commandstest.NewCliContext(map[string]string{
"config": cfgPath,
"homepath": grafDir,
})
require.NoError(t, err)
repoURL := c.PluginRepoURL()
require.Equal(t, "https://grafana-dev.com/plugins", repoURL)
token := c.GcomToken()
require.Equal(t, "token3", token)
})
t.Run("Should use config overrides parameter if it is set alongside config parameter", func(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
// GrafanaComApiUrl is set to the default path https://grafana.com/api
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
// overriding the GrafanaComApiUrl to https://grafana-dev.com
c, err := commandstest.NewCliContext(map[string]string{
"config": cfgPath,
"homepath": grafDir,
"configOverrides": "cfg:grafana_com.api_url=https://grafana-dev.com",
})
require.NoError(t, err)
repoURL := c.PluginRepoURL()
require.Equal(t, "https://grafana-dev.com/plugins", repoURL)
})
}