From 1134134e7274a5e2ebd847ea108c109fc966560c Mon Sep 17 00:00:00 2001 From: TommyStarK Date: Mon, 2 Jan 2023 14:40:55 +0100 Subject: [PATCH] kubelet/cm/containermap: Improving test coverage Signed-off-by: TommyStarK --- .../cm/containermap/container_map_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/kubelet/cm/containermap/container_map_test.go b/pkg/kubelet/cm/containermap/container_map_test.go index 8e58e2f2901..9dd5cbb24a4 100644 --- a/pkg/kubelet/cm/containermap/container_map_test.go +++ b/pkg/kubelet/cm/containermap/container_map_test.go @@ -62,26 +62,25 @@ func TestContainerMap(t *testing.T) { // Remove all entries from the containerMap, checking proper removal of // each along the way. - for i := range tc.containerNames { - cm.RemoveByContainerID(tc.containerIDs[i]) - containerID, err := cm.GetContainerID(tc.podUID, tc.containerNames[i]) + cm.Visit(func(podUID string, containerName string, containerID string) { + cm.RemoveByContainerID(containerID) + containerID, err := cm.GetContainerID(podUID, containerName) if err == nil { t.Errorf("unexpected retrieval of containerID after removal: %v", containerID) } - cm.Add(tc.podUID, tc.containerNames[i], tc.containerIDs[i]) + cm.Add(podUID, containerName, containerID) - cm.RemoveByContainerRef(tc.podUID, tc.containerNames[i]) - podUID, containerName, err := cm.GetContainerRef(tc.containerIDs[i]) + cm.RemoveByContainerRef(podUID, containerName) + id, cn, err := cm.GetContainerRef(containerID) if err == nil { - t.Errorf("unexpected retrieval of container reference after removal: (%v, %v)", podUID, containerName) + t.Errorf("unexpected retrieval of container reference after removal: (%v, %v)", id, cn) } - } + }) // Verify containerMap now empty. if len(cm) != 0 { t.Errorf("unexpected entries still in containerMap: %v", cm) } - } }