mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 05:02:35 +08:00
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:
@ -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)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user