TestNerdctlConfig validates the configuration precedence [CLI, Env, TOML, Default] and broken config rejection
(t *testing.T)
| 82 | |
| 83 | // TestNerdctlConfig validates the configuration precedence [CLI, Env, TOML, Default] and broken config rejection |
| 84 | func 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 |
| 127 | version = 2`), |
| 128 | }, |
| 129 | } |
| 130 | |
| 131 | testCase.Run(t) |
| 132 | } |