daemon/config: TestUnixValidateConfigurationErrors: use subtests

Use sub-tests and make sure we get the expected error

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-06-22 15:02:23 +02:00
parent 751222d907
commit 10e42f599a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -126,18 +126,21 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) {
func TestUnixValidateConfigurationErrors(t *testing.T) {
testCases := []struct {
config *Config
doc string
config *Config
expectedErr string
}{
// Can't override the stock runtime
{
doc: `cannot override the stock runtime`,
config: &Config{
Runtimes: map[string]types.Runtime{
StockRuntimeName: {},
},
},
expectedErr: `runtime name 'runc' is reserved`,
},
// Default runtime should be present in runtimes
{
doc: `default runtime should be present in runtimes`,
config: &Config{
Runtimes: map[string]types.Runtime{
"foo": {},
@ -146,13 +149,15 @@ func TestUnixValidateConfigurationErrors(t *testing.T) {
DefaultRuntime: "bar",
},
},
expectedErr: `specified default runtime 'bar' does not exist`,
},
}
for _, tc := range testCases {
err := Validate(tc.config)
if err == nil {
t.Fatalf("expected error, got nil for config %v", tc.config)
}
tc := tc
t.Run(tc.doc, func(t *testing.T) {
err := Validate(tc.config)
assert.ErrorContains(t, err, tc.expectedErr)
})
}
}