services/server/config: TestMergeConfigs(): use correctly formatted values

This updates the test to:

- Use correctly formatted values for RequiredPlugins and DisabledPlugins (values
  are expected to have a `io.containerd.` prefix). While not needed for the test
  to pass (no validation is performed), it's good to have these values in the
  correct format (in case we want to add validation at this stage).
- Set a `Version` for both (as version 1 / no version was deprecated)

The `Version` field in this test was used to verify the "integer override"
behavior; setting "Version: 2" for both would no longer cover that case. As there
are only 2 integer fields in the config (Version and OOMScore) and OOMScore was
already used in the test, I added separate test-cases for that.

Looking at the test, we should consider what we want the behaviour to be if the
override file does not specify a version (implicitly: version 1), or if the version
is different from the original one; do we want mergeConfig() to produce an error
when merging a v2 config with a v1 config (or v3 with v2)?

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-07 10:00:15 +01:00
parent 31bb8fef7e
commit f90219d472
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -31,8 +31,8 @@ func TestMergeConfigs(t *testing.T) {
a := &Config{
Version: 2,
Root: "old_root",
RequiredPlugins: []string{"old_plugin"},
DisabledPlugins: []string{"old_plugin"},
RequiredPlugins: []string{"io.containerd.old_plugin.v1"},
DisabledPlugins: []string{"io.containerd.old_plugin.v1"},
State: "old_state",
OOMScore: 1,
Timeouts: map[string]string{"a": "1"},
@ -40,8 +40,9 @@ func TestMergeConfigs(t *testing.T) {
}
b := &Config{
Version: 2,
Root: "new_root",
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
RequiredPlugins: []string{"io.containerd.new_plugin1.v1", "io.containerd.new_plugin2.v1"},
OOMScore: 2,
Timeouts: map[string]string{"b": "2"},
StreamProcessors: map[string]StreamProcessor{"1": {Path: "3"}},
@ -54,10 +55,24 @@ func TestMergeConfigs(t *testing.T) {
assert.Equal(t, "new_root", a.Root)
assert.Equal(t, "old_state", a.State)
assert.Equal(t, 2, a.OOMScore)
assert.Equal(t, []string{"old_plugin", "new_plugin1", "new_plugin2"}, a.RequiredPlugins)
assert.Equal(t, []string{"old_plugin"}, a.DisabledPlugins)
assert.Equal(t, []string{"io.containerd.old_plugin.v1", "io.containerd.new_plugin1.v1", "io.containerd.new_plugin2.v1"}, a.RequiredPlugins)
assert.Equal(t, []string{"io.containerd.old_plugin.v1"}, a.DisabledPlugins)
assert.Equal(t, map[string]string{"a": "1", "b": "2"}, a.Timeouts)
assert.Equal(t, map[string]StreamProcessor{"1": {Path: "3"}, "2": {Path: "5"}}, a.StreamProcessors)
// Verify overrides for integers
// https://github.com/containerd/containerd/blob/v1.6.0/services/server/config/config.go#L322-L323
a = &Config{Version: 2, OOMScore: 1}
b = &Config{Version: 2, OOMScore: 0} // OOMScore "not set / default"
err = mergeConfig(a, b)
assert.NoError(t, err)
assert.Equal(t, 1, a.OOMScore)
a = &Config{Version: 2, OOMScore: 1}
b = &Config{Version: 2, OOMScore: 0} // OOMScore "not set / default"
err = mergeConfig(a, b)
assert.NoError(t, err)
assert.Equal(t, 1, a.OOMScore)
}
func TestResolveImports(t *testing.T) {