|
| 1 | +/* |
| 2 | + Copyright The containerd Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package images |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/containerd/containerd/v2/plugins" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | +) |
| 27 | + |
| 28 | +func TestSandboxImageConfigMigration(t *testing.T) { |
| 29 | + image := "rancher/mirrored-pause:3.9-amd64" |
| 30 | + grpcCri := map[string]interface{}{ |
| 31 | + "sandbox_image": image, |
| 32 | + } |
| 33 | + pluginConfigs := map[string]interface{}{ |
| 34 | + string(plugins.GRPCPlugin) + ".cri": grpcCri, |
| 35 | + } |
| 36 | + configMigration(context.Background(), 2, pluginConfigs) |
| 37 | + v, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".images"] |
| 38 | + images := v.(map[string]interface{}) |
| 39 | + require.True(t, ok) |
| 40 | + v, ok = images["pinned_images"] |
| 41 | + require.True(t, ok) |
| 42 | + pinnedImages := v.(map[string]interface{}) |
| 43 | + v, ok = pinnedImages["sandbox"] |
| 44 | + require.True(t, ok) |
| 45 | + sandbox := v.(string) |
| 46 | + assert.Equal(t, image, sandbox) |
| 47 | +} |
| 48 | + |
| 49 | +func TestRegistryConfigMigration(t *testing.T) { |
| 50 | + path := "/etc/containerd/certs.d" |
| 51 | + grpcCri := map[string]interface{}{ |
| 52 | + "registry": map[string]interface{}{ |
| 53 | + "config_path": path, |
| 54 | + }, |
| 55 | + } |
| 56 | + pluginConfigs := map[string]interface{}{ |
| 57 | + string(plugins.GRPCPlugin) + ".cri": grpcCri, |
| 58 | + } |
| 59 | + configMigration(context.Background(), 2, pluginConfigs) |
| 60 | + v, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".images"] |
| 61 | + images := v.(map[string]interface{}) |
| 62 | + require.True(t, ok) |
| 63 | + v, ok = images["registry"] |
| 64 | + require.True(t, ok) |
| 65 | + registry := v.(map[string]interface{}) |
| 66 | + v, ok = registry["config_path"] |
| 67 | + require.True(t, ok) |
| 68 | + configPath := v.(string) |
| 69 | + assert.Equal(t, path, configPath) |
| 70 | +} |
0 commit comments