mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Adapt most CommandRunner tests to use FakeRuntime
This commit is contained in:
parent
b3197bb49b
commit
55f7b9b9b1
@ -937,12 +937,10 @@ func (f *fakeContainerCommandRunner) PortForward(pod *kubecontainer.Pod, port ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInContainerNoSuchPod(t *testing.T) {
|
func TestRunInContainerNoSuchPod(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeRuntime.PodList = []*kubecontainer.Pod{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
podNamespace := "nsFoo"
|
podNamespace := "nsFoo"
|
||||||
@ -961,36 +959,18 @@ func TestRunInContainerNoSuchPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunInContainer(t *testing.T) {
|
func TestRunInContainer(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
containerID := "abc1234"
|
containerID := "abc1234"
|
||||||
podName := "podFoo"
|
fakeRuntime.PodList = []*kubecontainer.Pod{
|
||||||
podNamespace := "nsFoo"
|
{ID: "12345678", Name: "podFoo", Namespace: "nsFoo", Containers: []*kubecontainer.Container{{Name: "containerFoo", ID: types.UID(containerID)}}},
|
||||||
containerName := "containerFoo"
|
|
||||||
|
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{
|
|
||||||
{
|
|
||||||
ID: containerID,
|
|
||||||
Names: []string{"/k8s_" + containerName + "_" + podName + "_" + podNamespace + "_12345678_42"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := []string{"ls"}
|
cmd := []string{"ls"}
|
||||||
_, err := kubelet.RunInContainer(
|
_, err := kubelet.RunInContainer("podFoo_nsFoo", "", "containerFoo", cmd)
|
||||||
kubecontainer.GetPodFullName(&api.Pod{
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
UID: "12345678",
|
|
||||||
Name: podName,
|
|
||||||
Namespace: podNamespace,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
"",
|
|
||||||
containerName,
|
|
||||||
cmd)
|
|
||||||
if fakeCommandRunner.ID != containerID {
|
if fakeCommandRunner.ID != containerID {
|
||||||
t.Errorf("unexpected Name: %s", fakeCommandRunner.ID)
|
t.Errorf("unexpected Name: %s", fakeCommandRunner.ID)
|
||||||
}
|
}
|
||||||
@ -1923,20 +1903,20 @@ func TestGetPodReadyCondition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecInContainerNoSuchPod(t *testing.T) {
|
func TestExecInContainerNoSuchPod(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
fakeRuntime.PodList = []*kubecontainer.Pod{}
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
podNamespace := "nsFoo"
|
podNamespace := "nsFoo"
|
||||||
containerName := "containerFoo"
|
containerID := "containerFoo"
|
||||||
err := kubelet.ExecInContainer(
|
err := kubelet.ExecInContainer(
|
||||||
kubecontainer.GetPodFullName(&api.Pod{ObjectMeta: api.ObjectMeta{Name: podName, Namespace: podNamespace}}),
|
kubecontainer.GetPodFullName(&api.Pod{ObjectMeta: api.ObjectMeta{Name: podName, Namespace: podNamespace}}),
|
||||||
"",
|
"",
|
||||||
containerName,
|
containerID,
|
||||||
[]string{"ls"},
|
[]string{"ls"},
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
@ -1952,21 +1932,17 @@ func TestExecInContainerNoSuchPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecInContainerNoSuchContainer(t *testing.T) {
|
func TestExecInContainerNoSuchContainer(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
podNamespace := "nsFoo"
|
podNamespace := "nsFoo"
|
||||||
containerID := "containerFoo"
|
containerID := "containerFoo"
|
||||||
|
fakeRuntime.PodList = []*kubecontainer.Pod{
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{
|
{ID: "12345678", Name: podName, Namespace: podNamespace, Containers: []*kubecontainer.Container{{Name: "bar", ID: "barID"}}},
|
||||||
{
|
|
||||||
ID: "notfound",
|
|
||||||
Names: []string{"/k8s_notfound_" + podName + "_" + podNamespace + "_12345678_42"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := kubelet.ExecInContainer(
|
err := kubelet.ExecInContainer(
|
||||||
@ -2006,10 +1982,10 @@ func (f *fakeReadWriteCloser) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecInContainer(t *testing.T) {
|
func TestExecInContainer(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
@ -2020,12 +1996,9 @@ func TestExecInContainer(t *testing.T) {
|
|||||||
stdout := &fakeReadWriteCloser{}
|
stdout := &fakeReadWriteCloser{}
|
||||||
stderr := &fakeReadWriteCloser{}
|
stderr := &fakeReadWriteCloser{}
|
||||||
tty := true
|
tty := true
|
||||||
|
fakeRuntime.PodList = []*kubecontainer.Pod{
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{
|
{ID: "12345678", Name: podName, Namespace: podNamespace, Containers: []*kubecontainer.Container{
|
||||||
{
|
{Name: containerID, ID: types.UID(containerID)}}},
|
||||||
ID: containerID,
|
|
||||||
Names: []string{"/k8s_" + containerID + "_" + podName + "_" + podNamespace + "_12345678_42"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := kubelet.ExecInContainer(
|
err := kubelet.ExecInContainer(
|
||||||
@ -2046,7 +2019,7 @@ func TestExecInContainer(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
if e, a := containerID, fakeCommandRunner.ID; e != a {
|
if e, a := containerID, fakeCommandRunner.ID; e != a {
|
||||||
t.Fatalf("container id: expected %s, got %s", e, a)
|
t.Fatalf("container name: expected %q, got %q", e, a)
|
||||||
}
|
}
|
||||||
if e, a := command, fakeCommandRunner.Cmd; !reflect.DeepEqual(e, a) {
|
if e, a := command, fakeCommandRunner.Cmd; !reflect.DeepEqual(e, a) {
|
||||||
t.Fatalf("command: expected '%v', got '%v'", e, a)
|
t.Fatalf("command: expected '%v', got '%v'", e, a)
|
||||||
@ -2066,11 +2039,11 @@ func TestExecInContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPortForwardNoSuchPod(t *testing.T) {
|
func TestPortForwardNoSuchPod(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
fakeRuntime.PodList = []*kubecontainer.Pod{}
|
||||||
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
@ -2092,21 +2065,18 @@ func TestPortForwardNoSuchPod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPortForwardNoSuchContainer(t *testing.T) {
|
func TestPortForwardNoSuchContainer(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
testKubelet := newTestKubeletWithFakeRuntime(t)
|
||||||
testKubelet := newTestKubelet(t)
|
|
||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
fakeDocker := testKubelet.fakeDocker
|
fakeRuntime := testKubelet.fakeRuntime
|
||||||
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
podName := "podFoo"
|
podName := "podFoo"
|
||||||
podNamespace := "nsFoo"
|
podNamespace := "nsFoo"
|
||||||
var port uint16 = 5000
|
var port uint16 = 5000
|
||||||
|
|
||||||
fakeDocker.ContainerList = []docker.APIContainers{
|
fakeRuntime.PodList = []*kubecontainer.Pod{
|
||||||
{
|
{ID: "12345678", Name: podName, Namespace: podNamespace, Containers: []*kubecontainer.Container{{Name: "bar", ID: "barID"}}},
|
||||||
ID: "notfound",
|
|
||||||
Names: []string{"/k8s_notfound_" + podName + "_" + podNamespace + "_12345678_42"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := kubelet.PortForward(
|
err := kubelet.PortForward(
|
||||||
@ -2172,7 +2142,7 @@ func TestPortForward(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
if e, a := infraContainerID, fakeCommandRunner.ID; e != a {
|
if e, a := infraContainerID, fakeCommandRunner.ID; e != a {
|
||||||
t.Fatalf("container id: expected %s, got %s", e, a)
|
t.Fatalf("container id: expected %q, got %q", e, a)
|
||||||
}
|
}
|
||||||
if e, a := port, fakeCommandRunner.Port; e != a {
|
if e, a := port, fakeCommandRunner.Port; e != a {
|
||||||
t.Fatalf("port: expected %v, got %v", e, a)
|
t.Fatalf("port: expected %v, got %v", e, a)
|
||||||
|
Loading…
Reference in New Issue
Block a user