Merge pull request #114760 from TommyStarK/unit-tests/pkg-kubelet-cm-containermap

kubelet/cm/containermap: Improving test coverage
This commit is contained in:
Kubernetes Prow Robot 2023-06-06 11:18:24 -07:00 committed by GitHub
commit 299b72c587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}
}
}