MCPcopy
hub / github.com/redspread/spread / TestContainerAttach

Function TestContainerAttach

pkg/entity/container_test.go:83–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestContainerAttach(t *testing.T) {
84 imageName := "to-be-attached"
85 image := testNewImage(t, imageName, kube.ObjectMeta{}, "test", []deploy.KubeObject{})
86
87 kubeContainer := testNewKubeContainer("test-container", "") // no image
88 container, err := NewContainer(kubeContainer, kube.ObjectMeta{}, "attach")
89 assert.NoError(t, err, "valid container")
90
91 _, err = container.Deployment()
92 assert.Error(t, err, "cannot be deployed without image")
93
94 err = container.Attach(image)
95 assert.NoError(t, err, "attach should be allowed")
96 children := container.children()
97 assert.Contains(t, children, image, "should have image as child")
98
99 images := container.Images()
100 assert.Len(t, images, 1, "only one image should exist")
101
102 kubeContainer.Image = imageName
103 pod := kube.Pod{
104 ObjectMeta: kube.ObjectMeta{
105 GenerateName: kubeContainer.Name,
106 Namespace: kube.NamespaceDefault,
107 },
108 Spec: kube.PodSpec{
109 Containers: []kube.Container{
110 kubeContainer,
111 },
112 RestartPolicy: kube.RestartPolicyAlways,
113 DNSPolicy: kube.DNSDefault,
114 },
115 }
116
117 expected := new(deploy.Deployment)
118 assert.NoError(t, expected.Add(&pod), "valid pod")
119 actual, err := container.Deployment()
120 assert.NoError(t, err, "deploy ok")
121
122 testDeploymentEqual(t, expected, actual)
123}
124
125func TestContainerBadObject(t *testing.T) {
126 // TODO: RESOLVE

Callers

nothing calls this directly

Calls 10

DeploymentMethod · 0.95
AttachMethod · 0.95
childrenMethod · 0.95
ImagesMethod · 0.95
testNewImageFunction · 0.85
testNewKubeContainerFunction · 0.85
NewContainerFunction · 0.85
testDeploymentEqualFunction · 0.85
LenMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected