@@ -125,3 +125,89 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1"
125
125
})
126
126
}
127
127
}
128
+
129
+ func TestConfig_RemoveRuntime (t * testing.T ) {
130
+ type fields struct {
131
+ hostFs afero.Fs
132
+ configPath string
133
+ }
134
+ type args struct {
135
+ shimPath string
136
+ }
137
+ tests := []struct {
138
+ name string
139
+ fields fields
140
+ args args
141
+ wantErr bool
142
+ wantFileErr bool
143
+ wantFileContent string
144
+ }{
145
+ {"missing shim config" , fields {
146
+ hostFs : newFixtureFs ("testdata/containerd/missing-containerd-shim-config" ),
147
+ configPath : "/etc/containerd/config.toml" ,
148
+ }, args {"/opt/kwasm/bin/containerd-shim-spin-v1" }, false , false , `[plugins]
149
+ [plugins."io.containerd.monitor.v1.cgroups"]
150
+ no_prometheus = false
151
+ [plugins."io.containerd.service.v1.diff-service"]
152
+ default = ["walking"]
153
+ [plugins."io.containerd.gc.v1.scheduler"]
154
+ pause_threshold = 0.02
155
+ deletion_threshold = 0
156
+ mutation_threshold = 100
157
+ schedule_delay = 0
158
+ startup_delay = "100ms"
159
+ [plugins."io.containerd.runtime.v2.task"]
160
+ platforms = ["linux/amd64"]
161
+ sched_core = true
162
+ [plugins."io.containerd.service.v1.tasks-service"]
163
+ blockio_config_file = ""
164
+ rdt_config_file = ""
165
+ ` },
166
+ {"missing config" , fields {
167
+ hostFs : newFixtureFs ("testdata/containerd/missing-containerd-config" ),
168
+ configPath : "/etc/containerd/config.toml" ,
169
+ }, args {"/opt/kwasm/bin/containerd-shim-spin-v1" }, true , true , `` },
170
+ {"existing shim config" , fields {
171
+ hostFs : newFixtureFs ("testdata/containerd/existing-containerd-shim-config" ),
172
+ configPath : "/etc/containerd/config.toml" ,
173
+ }, args {"/opt/kwasm/bin/containerd-shim-spin-v1" }, false , false , `[plugins]
174
+ [plugins."io.containerd.monitor.v1.cgroups"]
175
+ no_prometheus = false
176
+ [plugins."io.containerd.service.v1.diff-service"]
177
+ default = ["walking"]
178
+ [plugins."io.containerd.gc.v1.scheduler"]
179
+ pause_threshold = 0.02
180
+ deletion_threshold = 0
181
+ mutation_threshold = 100
182
+ schedule_delay = 0
183
+ startup_delay = "100ms"
184
+ [plugins."io.containerd.runtime.v2.task"]
185
+ platforms = ["linux/amd64"]
186
+ sched_core = true
187
+ [plugins."io.containerd.service.v1.tasks-service"]
188
+ blockio_config_file = ""
189
+ rdt_config_file = ""
190
+ ` },
191
+ }
192
+ for _ , tt := range tests {
193
+ t .Run (tt .name , func (t * testing.T ) {
194
+ c := & Config {
195
+ hostFs : tt .fields .hostFs ,
196
+ configPath : tt .fields .configPath ,
197
+ }
198
+ if err := c .RemoveRuntime (tt .args .shimPath ); (err != nil ) != tt .wantErr {
199
+ t .Errorf ("Config.RemoveRuntime() error = %v, wantErr %v" , err , tt .wantErr )
200
+ }
201
+
202
+ gotContent , err := afero .ReadFile (c .hostFs , c .configPath )
203
+ if (err != nil ) != tt .wantFileErr {
204
+ t .Errorf ("read %s error = %v, wantFileErr %v" , c .configPath , err , tt .wantFileErr )
205
+ return
206
+ }
207
+
208
+ if string (gotContent ) != tt .wantFileContent {
209
+ t .Errorf ("file content %s got = %s, want = %s" , c .configPath , string (gotContent ), tt .wantFileContent )
210
+ }
211
+ })
212
+ }
213
+ }
0 commit comments