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:
parent
751222d907
commit
10e42f599a
1 changed files with 12 additions and 7 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue