Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 0ac8363

Browse files
committed
Add integration test.
Signed-off-by: Lantao Liu <[email protected]>
1 parent 5e759f5 commit 0ac8363

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright 2018 The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package integration
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
"github.com/stretchr/testify/require"
24+
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
25+
)
26+
27+
// Test container lifecycle can work without image references.
28+
func TestContainerLifecycleWithoutImageRef(t *testing.T) {
29+
t.Log("Create a sandbox")
30+
sbConfig := PodSandboxConfig("sandbox", "container-lifecycle-without-image-ref")
31+
sb, err := runtimeService.RunPodSandbox(sbConfig)
32+
require.NoError(t, err)
33+
defer func() {
34+
assert.NoError(t, runtimeService.StopPodSandbox(sb))
35+
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
36+
}()
37+
38+
const (
39+
testImage = "busybox"
40+
containerName = "test-container"
41+
)
42+
t.Log("Pull test image")
43+
img, err := imageService.PullImage(&runtime.ImageSpec{Image: testImage}, nil)
44+
require.NoError(t, err)
45+
defer func() {
46+
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img}))
47+
}()
48+
49+
t.Log("Create test container")
50+
cnConfig := ContainerConfig(
51+
containerName,
52+
testImage,
53+
WithCommand("sleep", "1000"),
54+
)
55+
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
56+
require.NoError(t, err)
57+
require.NoError(t, runtimeService.StartContainer(cn))
58+
59+
t.Log("Remove test image")
60+
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img}))
61+
62+
t.Log("Container status should be running")
63+
status, err := runtimeService.ContainerStatus(cn)
64+
require.NoError(t, err)
65+
assert.Equal(t, status.GetState(), runtime.ContainerState_CONTAINER_RUNNING)
66+
67+
t.Logf("Stop container")
68+
err = runtimeService.StopContainer(cn, 1)
69+
assert.NoError(t, err)
70+
71+
t.Log("Container status should be exited")
72+
status, err = runtimeService.ContainerStatus(cn)
73+
require.NoError(t, err)
74+
assert.Equal(t, status.GetState(), runtime.ContainerState_CONTAINER_EXITED)
75+
}

integration/image_load_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestImageLoad(t *testing.T) {
3636
loadedImage := "docker.io/library/" + testImage
3737
_, err := exec.LookPath("docker")
3838
if err != nil {
39-
t.Skip("Docker is not available: %v", err)
39+
t.Skipf("Docker is not available: %v", err)
4040
}
4141
t.Logf("docker save image into tarball")
4242
output, err := exec.Command("docker", "pull", testImage).CombinedOutput()

0 commit comments

Comments
 (0)