Plugins: Tidy up CLI code (#67813)

* more tidying

* move some things around

* more tidying

* fix linter
This commit is contained in:
Will Browne
2023-05-08 10:58:47 +02:00
committed by GitHub
parent 0fc9a47779
commit e0e2535c96
16 changed files with 307 additions and 298 deletions

View File

@ -4,9 +4,10 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/plugins"
)
func TestVersionComparison(t *testing.T) {
@ -16,15 +17,23 @@ func TestVersionComparison(t *testing.T) {
{Version: "2.0.0"},
}
upgradeablePlugins := map[string]models.Plugin{
"0.0.0": {Versions: versions},
"1.0.0": {Versions: versions},
upgradeablePlugins := []struct {
have plugins.FoundPlugin
requested models.Plugin
}{
{
have: plugins.FoundPlugin{JSONData: plugins.JSONData{Info: plugins.Info{Version: "0.0.0"}}},
requested: models.Plugin{Versions: versions},
},
{
have: plugins.FoundPlugin{JSONData: plugins.JSONData{Info: plugins.Info{Version: "1.0.0"}}},
requested: models.Plugin{Versions: versions},
},
}
for k, v := range upgradeablePlugins {
val := v
t.Run(fmt.Sprintf("for %s should be true", k), func(t *testing.T) {
assert.True(t, shouldUpgrade(k, &val))
for _, v := range upgradeablePlugins {
t.Run(fmt.Sprintf("for %s should be true", v.have.JSONData.Info.Version), func(t *testing.T) {
require.True(t, shouldUpgrade(v.have, v.requested))
})
}
})
@ -35,15 +44,23 @@ func TestVersionComparison(t *testing.T) {
{Version: "2.0.0"},
}
shouldNotUpgrade := map[string]models.Plugin{
"2.0.0": {Versions: versions},
"6.0.0": {Versions: versions},
shouldNotUpgrade := []struct {
have plugins.FoundPlugin
requested models.Plugin
}{
{
have: plugins.FoundPlugin{JSONData: plugins.JSONData{Info: plugins.Info{Version: "2.0.0"}}},
requested: models.Plugin{Versions: versions},
},
{
have: plugins.FoundPlugin{JSONData: plugins.JSONData{Info: plugins.Info{Version: "6.0.0"}}},
requested: models.Plugin{Versions: versions},
},
}
for k, v := range shouldNotUpgrade {
val := v
t.Run(fmt.Sprintf("for %s should be false", k), func(t *testing.T) {
assert.False(t, shouldUpgrade(k, &val))
for _, v := range shouldNotUpgrade {
t.Run(fmt.Sprintf("for %s should be false", v.have.JSONData.Info.Version), func(t *testing.T) {
require.False(t, shouldUpgrade(v.have, v.requested))
})
}
})