|
@@ -5,6 +5,7 @@ import (
|
|
|
|
|
|
"github.com/containerd/containerd/log"
|
|
"github.com/containerd/containerd/log"
|
|
"github.com/docker/docker/daemon/config"
|
|
"github.com/docker/docker/daemon/config"
|
|
|
|
+ "github.com/google/go-cmp/cmp/cmpopts"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/pflag"
|
|
"github.com/spf13/pflag"
|
|
"gotest.tools/v3/assert"
|
|
"gotest.tools/v3/assert"
|
|
@@ -223,3 +224,72 @@ func TestConfigureDaemonLogs(t *testing.T) {
|
|
// TODO (thaJeztah): add more aliases in log package
|
|
// TODO (thaJeztah): add more aliases in log package
|
|
assert.Check(t, is.Equal(logrus.WarnLevel, log.GetLevel()))
|
|
assert.Check(t, is.Equal(logrus.WarnLevel, log.GetLevel()))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestCDISpecDirs(t *testing.T) {
|
|
|
|
+ testCases := []struct {
|
|
|
|
+ description string
|
|
|
|
+ configContent string
|
|
|
|
+ experimental bool
|
|
|
|
+ specDirs []string
|
|
|
|
+ expectedCDISpecDirs []string
|
|
|
|
+ }{
|
|
|
|
+ {
|
|
|
|
+ description: "experimental and no spec dirs specified returns default",
|
|
|
|
+ specDirs: nil,
|
|
|
|
+ experimental: true,
|
|
|
|
+ expectedCDISpecDirs: []string{"/etc/cdi", "/var/run/cdi"},
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ description: "experimental and specified spec dirs are returned",
|
|
|
|
+ specDirs: []string{"/foo/bar", "/baz/qux"},
|
|
|
|
+ experimental: true,
|
|
|
|
+ expectedCDISpecDirs: []string{"/foo/bar", "/baz/qux"},
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ description: "experimental and empty string as spec dir returns empty slice",
|
|
|
|
+ specDirs: []string{""},
|
|
|
|
+ experimental: true,
|
|
|
|
+ expectedCDISpecDirs: []string{},
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ description: "experimental and empty config option returns empty slice",
|
|
|
|
+ configContent: `{"cdi-spec-dirs": []}`,
|
|
|
|
+ experimental: true,
|
|
|
|
+ expectedCDISpecDirs: []string{},
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ description: "non-experimental and no spec dirs specified returns no cdi spec dirs",
|
|
|
|
+ specDirs: nil,
|
|
|
|
+ experimental: false,
|
|
|
|
+ expectedCDISpecDirs: nil,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ description: "non-experimental and specified spec dirs returns no cdi spec dirs",
|
|
|
|
+ specDirs: []string{"/foo/bar", "/baz/qux"},
|
|
|
|
+ experimental: false,
|
|
|
|
+ expectedCDISpecDirs: nil,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, tc := range testCases {
|
|
|
|
+ t.Run(tc.description, func(t *testing.T) {
|
|
|
|
+ tempFile := fs.NewFile(t, "config", fs.WithContent(tc.configContent))
|
|
|
|
+ defer tempFile.Remove()
|
|
|
|
+
|
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
|
+
|
|
|
|
+ flags := opts.flags
|
|
|
|
+ for _, specDir := range tc.specDirs {
|
|
|
|
+ assert.Check(t, flags.Set("cdi-spec-dir", specDir))
|
|
|
|
+ }
|
|
|
|
+ if tc.experimental {
|
|
|
|
+ assert.Check(t, flags.Set("experimental", "true"))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+
|
|
|
|
+ assert.Check(t, is.DeepEqual(tc.expectedCDISpecDirs, loadedConfig.CDISpecDirs, cmpopts.EquateEmpty()))
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+}
|