2018-08-29 23:26:44 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2018-08-29 23:26:44 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPluginConfig_Merge(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2018-08-29 23:26:44 +00:00
|
|
|
require := require.New(t)
|
|
|
|
a := &PluginConfig{
|
|
|
|
Name: "foo",
|
|
|
|
Args: []string{"bar"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"baz": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
e1 := &PluginConfig{
|
|
|
|
Name: "replaced",
|
|
|
|
Args: []string{"bar"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"baz": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
o1 := a.Merge(&PluginConfig{Name: "replaced"})
|
|
|
|
require.Equal(e1, o1)
|
|
|
|
|
|
|
|
e2 := &PluginConfig{
|
|
|
|
Name: "foo",
|
|
|
|
Args: []string{"replaced", "another"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"baz": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
o2 := a.Merge(&PluginConfig{
|
|
|
|
Args: []string{"replaced", "another"},
|
|
|
|
})
|
|
|
|
require.Equal(e2, o2)
|
|
|
|
|
|
|
|
e3 := &PluginConfig{
|
|
|
|
Name: "foo",
|
|
|
|
Args: []string{"bar"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"replaced": 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
o3 := a.Merge(&PluginConfig{
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"replaced": 1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.Equal(e3, o3)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPluginConfigSet_Merge(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2018-08-29 23:26:44 +00:00
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
a := &PluginConfig{
|
|
|
|
Name: "a",
|
|
|
|
Args: []string{"a1"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"a1": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
b1 := &PluginConfig{
|
|
|
|
Name: "b",
|
|
|
|
Args: []string{"b1"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"b1": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
b2 := &PluginConfig{
|
|
|
|
Name: "b",
|
|
|
|
Args: []string{"b2"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"b2": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
c := &PluginConfig{
|
|
|
|
Name: "c",
|
|
|
|
Args: []string{"c"},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"c1": true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
s1 := []*PluginConfig{a, b1}
|
|
|
|
s2 := []*PluginConfig{b2, c}
|
|
|
|
|
|
|
|
out := PluginConfigSetMerge(s1, s2)
|
|
|
|
sort.Slice(out, func(i, j int) bool {
|
|
|
|
return out[i].Name < out[j].Name
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := []*PluginConfig{a, b2, c}
|
|
|
|
require.EqualValues(expected, out)
|
|
|
|
}
|