Chore: Making the plugin install commands respect the config parameter (#86578)

Currently the grafana cli plugin commands are not reacting to the --config parameter. This PR make it possible to use config to define the plugin endpoints via config as an alternative to providing the --repo flag.
This commit is contained in:
Timur Olzhabayev
2024-04-22 10:29:25 +02:00
committed by GitHub
parent 2a39f1f7ce
commit 951916c668
3 changed files with 103 additions and 0 deletions

View File

@ -4,7 +4,9 @@ import (
"fmt"
"testing"
"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"
)
@ -78,3 +80,60 @@ func TestValidateInput(t *testing.T) {
})
}
}
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{
"repo": "https://example.com",
})
require.NoError(t, err)
require.Equal(t, "https://example.com", c.PluginRepoURL())
})
t.Run("Should use provided repo parameter even if config is set", func(t *testing.T) {
c, err := commandstest.NewCliContext(map[string]string{
"repo": "https://example.com",
"config": "/tmp/config.ini",
})
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",
})
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)
})
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)
// 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)
})
}