Fix toml plugin decoding
Do not rely on toml metadata when decoding plugin's configs as it's not possible to merge toml.MetaData structs during import. Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
		| @@ -23,6 +23,8 @@ import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"gotest.tools/assert" | ||||
|  | ||||
| 	"github.com/containerd/containerd/plugin" | ||||
| ) | ||||
|  | ||||
| func TestMergeConfigs(t *testing.T) { | ||||
| @@ -161,3 +163,28 @@ imports = ["data1.toml", "data2.toml"] | ||||
| 		filepath.Join(tempDir, "data2.toml"), | ||||
| 	}, out.Imports) | ||||
| } | ||||
|  | ||||
| func TestDecodePlugin(t *testing.T) { | ||||
| 	data := ` | ||||
| version = 1 | ||||
| [plugins.linux] | ||||
|   shim_debug = true | ||||
| ` | ||||
|  | ||||
| 	tempDir, err := ioutil.TempDir("", "containerd_") | ||||
| 	assert.NilError(t, err) | ||||
| 	defer os.RemoveAll(tempDir) | ||||
|  | ||||
| 	path := filepath.Join(tempDir, "config.toml") | ||||
| 	err = ioutil.WriteFile(path, []byte(data), 0600) | ||||
| 	assert.NilError(t, err) | ||||
|  | ||||
| 	var out Config | ||||
| 	err = LoadConfig(path, &out) | ||||
| 	assert.NilError(t, err) | ||||
|  | ||||
| 	pluginConfig := map[string]interface{}{} | ||||
| 	_, err = out.Decode(&plugin.Registration{ID: "linux", Config: &pluginConfig}) | ||||
| 	assert.NilError(t, err) | ||||
| 	assert.Equal(t, true, pluginConfig["shim_debug"]) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Maksym Pavlenko
					Maksym Pavlenko