|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | "github.com/docker/docker/api/types/container" |
| 7 | + dopts "github.com/docker/docker/internal/opts" |
7 | 8 | "github.com/docker/docker/opts" |
8 | 9 | "github.com/spf13/pflag" |
9 | 10 | "gotest.tools/v3/assert" |
@@ -121,6 +122,72 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) { |
121 | 122 | assert.Check(t, is.Equal(int64(expectedValue), cc.ShmSize.Value())) |
122 | 123 | } |
123 | 124 |
|
| 125 | +func TestDaemonConfigurationFeatures(t *testing.T) { |
| 126 | + tests := []struct { |
| 127 | + name, config, flags string |
| 128 | + expectedValue map[string]bool |
| 129 | + expectedErr string |
| 130 | + }{ |
| 131 | + { |
| 132 | + name: "enable from file", |
| 133 | + config: `{"features": {"containerd-snapshotter": true}}`, |
| 134 | + expectedValue: map[string]bool{"containerd-snapshotter": true}, |
| 135 | + }, |
| 136 | + { |
| 137 | + name: "enable from flags", |
| 138 | + config: `{}`, |
| 139 | + flags: "containerd-snapshotter=true", |
| 140 | + expectedValue: map[string]bool{"containerd-snapshotter": true}, |
| 141 | + }, |
| 142 | + { |
| 143 | + name: "disable from file", |
| 144 | + config: `{"features": {"containerd-snapshotter": false}}`, |
| 145 | + expectedValue: map[string]bool{"containerd-snapshotter": false}, |
| 146 | + }, |
| 147 | + { |
| 148 | + name: "disable from flags", |
| 149 | + config: `{}`, |
| 150 | + flags: "containerd-snapshotter=false", |
| 151 | + expectedValue: map[string]bool{"containerd-snapshotter": false}, |
| 152 | + }, |
| 153 | + { |
| 154 | + name: "conflict", |
| 155 | + config: `{"features": {"containerd-snapshotter": true}}`, |
| 156 | + flags: "containerd-snapshotter=true", |
| 157 | + expectedErr: `the following directives are specified both as a flag and in the configuration file: features: (from flag: map[containerd-snapshotter:true], from file: map[containerd-snapshotter:true])`, |
| 158 | + }, |
| 159 | + { |
| 160 | + name: "invalid config value", |
| 161 | + config: `{"features": {"containerd-snapshotter": "not-a-boolean"}}`, |
| 162 | + expectedErr: `json: cannot unmarshal string into Go struct field Config.features of type bool`, |
| 163 | + }, |
| 164 | + } |
| 165 | + |
| 166 | + for _, tc := range tests { |
| 167 | + tc := tc |
| 168 | + |
| 169 | + t.Run(tc.name, func(t *testing.T) { |
| 170 | + c, err := New() |
| 171 | + assert.NilError(t, err) |
| 172 | + |
| 173 | + configFile := makeConfigFile(t, tc.config) |
| 174 | + flags := pflag.NewFlagSet("test", pflag.ContinueOnError) |
| 175 | + flags.Var(dopts.NewNamedSetOpts("features", c.Features), "feature", "Enable feature in the daemon") |
| 176 | + if tc.flags != "" { |
| 177 | + err = flags.Set("feature", tc.flags) |
| 178 | + assert.NilError(t, err) |
| 179 | + } |
| 180 | + cc, err := MergeDaemonConfigurations(c, flags, configFile) |
| 181 | + if tc.expectedErr != "" { |
| 182 | + assert.Error(t, err, tc.expectedErr) |
| 183 | + } else { |
| 184 | + assert.NilError(t, err) |
| 185 | + assert.Check(t, is.DeepEqual(tc.expectedValue, cc.Features)) |
| 186 | + } |
| 187 | + }) |
| 188 | + } |
| 189 | +} |
| 190 | + |
124 | 191 | func TestUnixGetInitPath(t *testing.T) { |
125 | 192 | testCases := []struct { |
126 | 193 | config *Config |
|
0 commit comments