mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 02:32:19 +08:00
Plugins: Tidy up CLI code (#67813)
* more tidying * move some things around * more tidying * fix linter
This commit is contained in:
@ -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))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user