MCPcopy Index your code
hub / github.com/containerd/containerd / TestBuildLabels

Function TestBuildLabels

internal/cri/util/util_test.go:146–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func 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
177func TestGenerateUserString(t *testing.T) {
178 type testcase struct {

Callers

nothing calls this directly

Calls 2

BuildLabelsFunction · 0.85
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…