upgrade_all_command_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package commands
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestVersionComparsion(t *testing.T) {
  9. t.Run("Validate that version is outdated", func(t *testing.T) {
  10. versions := []models.Version{
  11. {Version: "1.1.1"},
  12. {Version: "2.0.0"},
  13. }
  14. upgradeablePlugins := map[string]models.Plugin{
  15. "0.0.0": {Versions: versions},
  16. "1.0.0": {Versions: versions},
  17. }
  18. for k, v := range upgradeablePlugins {
  19. t.Run(fmt.Sprintf("for %s should be true", k), func(t *testing.T) {
  20. assert.True(t, shouldUpgrade(k, &v))
  21. })
  22. }
  23. })
  24. t.Run("Validate that version is ok", func(t *testing.T) {
  25. versions := []models.Version{
  26. {Version: "1.1.1"},
  27. {Version: "2.0.0"},
  28. }
  29. shouldNotUpgrade := map[string]models.Plugin{
  30. "2.0.0": {Versions: versions},
  31. "6.0.0": {Versions: versions},
  32. }
  33. for k, v := range shouldNotUpgrade {
  34. t.Run(fmt.Sprintf("for %s should be false", k), func(t *testing.T) {
  35. assert.False(t, shouldUpgrade(k, &v))
  36. })
  37. }
  38. })
  39. }