Merge pull request #100424 from yangjunmyfm192085/run-test30

Add test cases of kubelet_pods_test.go.
This commit is contained in:
Kubernetes Prow Robot 2022-03-17 00:41:19 -07:00 committed by GitHub
commit ba1c42892f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2865,28 +2865,43 @@ func TestGetExec(t *testing.T) {
) )
var ( var (
podFullName = kubecontainer.GetPodFullName(podWithUIDNameNs(podUID, podName, podNamespace)) podFullName = kubecontainer.GetPodFullName(podWithUIDNameNs(podUID, podName, podNamespace))
command = []string{"ls"}
) )
testcases := []struct { testcases := []struct {
description string description string
podFullName string podFullName string
container string container string
command []string
expectError bool expectError bool
}{{ }{{
description: "success case", description: "success case",
podFullName: podFullName, podFullName: podFullName,
container: containerID, container: containerID,
command: []string{"ls"},
expectError: false,
}, { }, {
description: "no such pod", description: "no such pod",
podFullName: "bar" + podFullName, podFullName: "bar" + podFullName,
container: containerID, container: containerID,
command: []string{"ls"},
expectError: true, expectError: true,
}, { }, {
description: "no such container", description: "no such container",
podFullName: podFullName, podFullName: podFullName,
container: "containerBar", container: "containerBar",
command: []string{"ls"},
expectError: true, expectError: true,
}, {
description: "null exec command",
podFullName: podFullName,
container: containerID,
expectError: false,
}, {
description: "multi exec commands",
podFullName: podFullName,
container: containerID,
command: []string{"bash", "-c", "ls"},
expectError: false,
}} }}
for _, tc := range testcases { for _, tc := range testcases {
@ -2911,7 +2926,7 @@ func TestGetExec(t *testing.T) {
kubelet.containerRuntime = fakeRuntime kubelet.containerRuntime = fakeRuntime
kubelet.streamingRuntime = fakeRuntime kubelet.streamingRuntime = fakeRuntime
redirect, err := kubelet.GetExec(tc.podFullName, podUID, tc.container, command, remotecommand.Options{}) redirect, err := kubelet.GetExec(tc.podFullName, podUID, tc.container, tc.command, remotecommand.Options{})
if tc.expectError { if tc.expectError {
assert.Error(t, err, description) assert.Error(t, err, description)
} else { } else {