@@ -22,7 +22,7 @@ import (
2222 "sigs.k8s.io/kind/pkg/internal/assert"
2323)
2424
25- func TestTOML (t * testing.T ) {
25+ func TestContainerdTOML (t * testing.T ) {
2626 t .Parallel ()
2727 type testCase struct {
2828 Name string
@@ -39,15 +39,48 @@ func TestTOML(t *testing.T) {
3939 ExpectError : true ,
4040 ExpectOutput : "" ,
4141 },
42+ {
43+ Name : "invalid containerd versioning" ,
44+ ToPatch : `version = "five"` ,
45+ ExpectError : true ,
46+ ExpectOutput : "" ,
47+ },
4248 {
4349 Name : "no patches" ,
44- ToPatch : `disabled_plugins = ["restart"]
50+ ToPatch : `version = 2
51+ disabled_plugins = ["restart"]
4552[plugins.linux]
4653 shim_debug = true
4754[plugins.cri.containerd.runtimes.runsc]
4855 runtime_type = "io.containerd.runsc.v1"` ,
4956 ExpectError : false ,
5057 ExpectOutput : `disabled_plugins = ["restart"]
58+ version = 2
59+
60+ [plugins]
61+ [plugins.cri]
62+ [plugins.cri.containerd]
63+ [plugins.cri.containerd.runtimes]
64+ [plugins.cri.containerd.runtimes.runsc]
65+ runtime_type = "io.containerd.runsc.v1"
66+ [plugins.linux]
67+ shim_debug = true
68+ ` ,
69+ },
70+ {
71+ Name : "Only matching patches" ,
72+ ToPatch : `version = 2
73+
74+ disabled_plugins = ["restart"]
75+
76+ [plugins.linux]
77+ shim_debug = true
78+ [plugins.cri.containerd.runtimes.runsc]
79+ runtime_type = "io.containerd.runsc.v1"` ,
80+ Patches : []string {"version = 3\n disabled_plugins=[\" bar\" ]" , "version = 2\n disabled_plugins=[\" baz\" ]" },
81+ ExpectError : false ,
82+ ExpectOutput : `disabled_plugins = ["baz"]
83+ version = 2
5184
5285[plugins]
5386 [plugins.cri]
@@ -61,7 +94,8 @@ func TestTOML(t *testing.T) {
6194 },
6295 {
6396 Name : "invalid patch TOML" ,
64- ToPatch : `disabled_plugins = ["restart"]
97+ ToPatch : `version = 2
98+ disabled_plugins = ["restart"]
6599[plugins.linux]
66100 shim_debug = true
67101[plugins.cri.containerd.runtimes.runsc]
@@ -81,14 +115,16 @@ func TestTOML(t *testing.T) {
81115 },
82116 {
83117 Name : "trivial patch" ,
84- ToPatch : `disabled_plugins = ["restart"]
118+ ToPatch : `version = 2
119+ disabled_plugins = ["restart"]
85120[plugins.linux]
86121 shim_debug = true
87122[plugins.cri.containerd.runtimes.runsc]
88123 runtime_type = "io.containerd.runsc.v1"` ,
89124 Patches : []string {`disabled_plugins=[]` },
90125 ExpectError : false ,
91126 ExpectOutput : `disabled_plugins = []
127+ version = 2
92128
93129[plugins]
94130 [plugins.cri]
@@ -102,14 +138,17 @@ func TestTOML(t *testing.T) {
102138 },
103139 {
104140 Name : "trivial 6902 patch" ,
105- ToPatch : `disabled_plugins = ["restart"]
141+ ToPatch : `version = 2
142+ disabled_plugins = ["restart"]
106143[plugins.linux]
107144 shim_debug = true
108145[plugins.cri.containerd.runtimes.runsc]
109146 runtime_type = "io.containerd.runsc.v1"` ,
110147 PatchesJSON6902 : []string {`[{"op": "remove", "path": "/disabled_plugins"}]` },
111148 ExpectError : false ,
112- ExpectOutput : `[plugins]
149+ ExpectOutput : `version = 2
150+
151+ [plugins]
113152 [plugins.cri]
114153 [plugins.cri.containerd]
115154 [plugins.cri.containerd.runtimes]
@@ -121,15 +160,18 @@ func TestTOML(t *testing.T) {
121160 },
122161 {
123162 Name : "trivial patch and trivial 6902 patch" ,
124- ToPatch : `disabled_plugins = ["restart"]
163+ ToPatch : `version = 2
164+ disabled_plugins = ["restart"]
125165[plugins.linux]
126166 shim_debug = true
127167[plugins.cri.containerd.runtimes.runsc]
128168 runtime_type = "io.containerd.runsc.v1"` ,
129169 Patches : []string {`disabled_plugins=["foo"]` },
130170 PatchesJSON6902 : []string {`[{"op": "remove", "path": "/disabled_plugins"}]` },
131171 ExpectError : false ,
132- ExpectOutput : `[plugins]
172+ ExpectOutput : `version = 2
173+
174+ [plugins]
133175 [plugins.cri]
134176 [plugins.cri.containerd]
135177 [plugins.cri.containerd.runtimes]
@@ -160,7 +202,8 @@ func TestTOML(t *testing.T) {
160202 },
161203 {
162204 Name : "patch registry" ,
163- ToPatch : `disabled_plugins = ["restart"]
205+ ToPatch : `version = 2
206+ disabled_plugins = ["restart"]
164207[plugins.linux]
165208 shim_debug = true
166209[plugins.cri.containerd.runtimes.runsc]
@@ -170,6 +213,7 @@ func TestTOML(t *testing.T) {
170213 endpoint = ["http://registry:5000"]` },
171214 ExpectError : false ,
172215 ExpectOutput : `disabled_plugins = ["restart"]
216+ version = 2
173217
174218[plugins]
175219 [plugins.cri]
@@ -190,7 +234,7 @@ func TestTOML(t *testing.T) {
190234 tc := tc // capture test case
191235 t .Run (tc .Name , func (t * testing.T ) {
192236 t .Parallel ()
193- out , err := TOML (tc .ToPatch , tc .Patches , tc .PatchesJSON6902 )
237+ out , err := ContainerdTOML (tc .ToPatch , tc .Patches , tc .PatchesJSON6902 )
194238 assert .ExpectError (t , tc .ExpectError , err )
195239 if err == nil {
196240 assert .StringEqual (t , tc .ExpectOutput , out )
0 commit comments