MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestNerdctlConfig

Function TestNerdctlConfig

cmd/nerdctl/main_test.go:84–132  ·  view source on GitHub ↗

TestNerdctlConfig validates the configuration precedence [CLI, Env, TOML, Default] and broken config rejection

(t *testing.T)

Source from the content-addressed store, hash-verified

82
83// TestNerdctlConfig validates the configuration precedence [CLI, Env, TOML, Default] and broken config rejection
84func TestNerdctlConfig(t *testing.T) {
85 testCase := nerdtest.Setup()
86
87 // Docker does not support nerdctl.toml obviously
88 testCase.Require = require.Not(nerdtest.Docker)
89
90 testCase.SubTests = []*test.Case{
91 {
92 Description: "Default",
93 Command: test.Command("info", "-f", "{{.Driver}}"),
94 Expected: test.Expects(0, nil, expect.Equals(defaults.DefaultSnapshotter+"\n")),
95 },
96 {
97 Description: "TOML > Default",
98 Command: test.Command("info", "-f", "{{.Driver}}"),
99 Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-toml\n")),
100 Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`),
101 },
102 {
103 Description: "Cli > TOML > Default",
104 Command: test.Command("info", "-f", "{{.Driver}}", "--snapshotter=dummy-snapshotter-via-cli"),
105 Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-cli\n")),
106 Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`),
107 },
108 {
109 Description: "Env > TOML > Default",
110 Command: test.Command("info", "-f", "{{.Driver}}"),
111 Env: map[string]string{"CONTAINERD_SNAPSHOTTER": "dummy-snapshotter-via-env"},
112 Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-env\n")),
113 Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`),
114 },
115 {
116 Description: "Cli > Env > TOML > Default",
117 Command: test.Command("info", "-f", "{{.Driver}}", "--snapshotter=dummy-snapshotter-via-cli"),
118 Env: map[string]string{"CONTAINERD_SNAPSHOTTER": "dummy-snapshotter-via-env"},
119 Expected: test.Expects(0, nil, expect.Equals("dummy-snapshotter-via-cli\n")),
120 Config: test.WithConfig(nerdtest.NerdctlToml, `snapshotter = "dummy-snapshotter-via-toml"`),
121 },
122 {
123 Description: "Broken config",
124 Command: test.Command("info"),
125 Expected: test.Expects(1, []error{errors.New("failed to load nerdctl config")}, nil),
126 Config: test.WithConfig(nerdtest.NerdctlToml, `# containerd config, not nerdctl config
127version = 2`),
128 },
129 }
130
131 testCase.Run(t)
132}

Callers

nothing calls this directly

Calls 3

SetupFunction · 0.92
CommandMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…