mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-05 07:31:11 +02:00
Improved notification tests, refactor ConfigurationType to Phase
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -77,10 +75,10 @@ func Must(plugin *Plugin, err error) Plugin {
|
||||
}
|
||||
|
||||
// VerifyDependencies checks if all plugins have compatible versions
|
||||
func VerifyDependencies(values ...map[Plugin][]Plugin) bool {
|
||||
func VerifyDependencies(values ...map[Plugin][]Plugin) []string {
|
||||
var messages []string
|
||||
// key - plugin name, value array of versions
|
||||
allPlugins := make(map[string][]Plugin)
|
||||
valid := true
|
||||
|
||||
for _, value := range values {
|
||||
for rootPlugin, plugins := range value {
|
||||
@@ -105,18 +103,17 @@ func VerifyDependencies(values ...map[Plugin][]Plugin) bool {
|
||||
for _, firstVersion := range versions {
|
||||
for _, secondVersion := range versions {
|
||||
if firstVersion.Version != secondVersion.Version {
|
||||
log.Log.V(log.VWarn).Info(fmt.Sprintf("Plugin '%s' requires version '%s' but plugin '%s' requires '%s' for plugin '%s'",
|
||||
messages = append(messages, fmt.Sprintf("Plugin '%s' requires version '%s' but plugin '%s' requires '%s' for plugin '%s'",
|
||||
firstVersion.rootPluginNameAndVersion,
|
||||
firstVersion.Version,
|
||||
secondVersion.rootPluginNameAndVersion,
|
||||
secondVersion.Version,
|
||||
pluginName,
|
||||
))
|
||||
valid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return valid
|
||||
return messages
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, true, got)
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
t.Run("happy, two root plugins with one depended plugin with the same version", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -30,7 +30,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, true, got)
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
t.Run("happy, two plugin names with names with underscores", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -42,7 +42,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, true, got)
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
t.Run("happy, two plugin names with uppercase names", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -54,7 +54,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, true, got)
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
t.Run("fail, two root plugins have different versions", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -66,7 +66,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, false, got)
|
||||
assert.NotNil(t, got)
|
||||
})
|
||||
t.Run("happy, no version collision with two sperate plugins lists", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -80,7 +80,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins, extraPlugins)
|
||||
assert.Equal(t, true, got)
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
t.Run("fail, dependent plugins have different versions", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -92,7 +92,7 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins)
|
||||
assert.Equal(t, false, got)
|
||||
assert.NotNil(t, got)
|
||||
})
|
||||
t.Run("fail, root and dependent plugins have different versions", func(t *testing.T) {
|
||||
basePlugins := map[Plugin][]Plugin{
|
||||
@@ -106,6 +106,6 @@ func TestVerifyDependencies(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := VerifyDependencies(basePlugins, extraPlugins)
|
||||
assert.Equal(t, false, got)
|
||||
assert.NotNil(t, got)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user