(t *testing.T)
| 144 | } |
| 145 | |
| 146 | func TestBuildLabels(t *testing.T) { |
| 147 | imageConfigLabels := map[string]string{ |
| 148 | "a": "z", |
| 149 | "d": "y", |
| 150 | "long-label": strings.Repeat("example", 10000), |
| 151 | "containerd.io/restart.policy": "always", |
| 152 | "io.cri-containerd.image": "managed", |
| 153 | } |
| 154 | configLabels := map[string]string{ |
| 155 | "a": "b", |
| 156 | "c": "d", |
| 157 | // reserved namespaces are only filtered for image config labels, not |
| 158 | // for labels from the CRI request |
| 159 | "containerd.io/restart.status": "stopped", |
| 160 | } |
| 161 | newLabels := BuildLabels(configLabels, imageConfigLabels, crilabels.ContainerKindSandbox) |
| 162 | assert.Len(t, newLabels, 5) |
| 163 | assert.Equal(t, "b", newLabels["a"]) |
| 164 | assert.Equal(t, "d", newLabels["c"]) |
| 165 | assert.Equal(t, "y", newLabels["d"]) |
| 166 | assert.Equal(t, "stopped", newLabels["containerd.io/restart.status"]) |
| 167 | assert.Equal(t, crilabels.ContainerKindSandbox, newLabels[crilabels.ContainerKindLabel]) |
| 168 | assert.NotContains(t, newLabels, "long-label") |
| 169 | assert.NotContains(t, newLabels, "containerd.io/restart.policy") |
| 170 | assert.NotContains(t, newLabels, "io.cri-containerd.image") |
| 171 | |
| 172 | newLabels["a"] = "e" |
| 173 | assert.Empty(t, configLabels[crilabels.ContainerKindLabel], "should not add new labels into original label") |
| 174 | assert.Equal(t, "b", configLabels["a"], "change in new labels should not affect original label") |
| 175 | } |
| 176 | |
| 177 | func TestGenerateUserString(t *testing.T) { |
| 178 | type testcase struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…