Skip to content

Commit

Permalink
Merge pull request kata-containers#39 from GabyCT/topic/dockerintegra…
Browse files Browse the repository at this point in the history
…tion

tests: Add docker integration test for attach, commit, cp and create.
  • Loading branch information
jcvenegas authored Jan 23, 2018
2 parents 0e6b88b + 1a7d60f commit 271fa11
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
42 changes: 42 additions & 0 deletions integration/docker/attach_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("docker attach", func() {
var (
id string
exitCode int
containerExitCode int
destroyTimeout int
)

BeforeEach(func() {
containerExitCode = 13
destroyTimeout = 3
id = randomDockerName()
_, _, exitCode = dockerRun("--name", id, "-d", Image, "sh", "-c",
fmt.Sprintf("sleep %d && exit %d", destroyTimeout, containerExitCode))
Expect(exitCode).To(Equal(0))
})

AfterEach(func() {
Expect(RemoveDockerContainer(id)).To(BeTrue())
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("check attach functionality", func() {
It("should attach exit code", func() {
_, _, exitCode = dockerAttach(id)
Expect(exitCode).To(Equal(containerExitCode))
})
})
})
48 changes: 48 additions & 0 deletions integration/docker/commit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("docker commit", func() {
var (
id string
exitCode int
stdout string
)

BeforeEach(func() {
id = randomDockerName()
_, _, exitCode = dockerRun("-td", "--name", id, Image, "sh")
Expect(exitCode).To(Equal(0))
})

AfterEach(func() {
Expect(RemoveDockerContainer(id)).To(BeTrue())
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("commit a container with new configurations", func() {
It("should have the new configurations", func() {
imageName := "test/container-test"
_, _, exitCode = dockerCommit("-m", "test_commit", id, imageName)
Expect(exitCode).To(Equal(0))

stdout, _, exitCode = dockerImages()
Expect(exitCode).To(Equal(0))
Expect(stdout).To(ContainSubstring(imageName))

_, _, exitCode = dockerRmi(imageName)
Expect(exitCode).To(Equal(0))

stdout, _, exitCode = dockerImages()
Expect(exitCode).To(Equal(0))
Expect(stdout).NotTo(ContainSubstring(imageName))
})
})
})
52 changes: 52 additions & 0 deletions integration/docker/cp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
"io/ioutil"
"os"
"path"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("docker cp", func() {
var (
id string
exitCode int
stdout string
)

BeforeEach(func() {
id = randomDockerName()
_, _, exitCode = dockerRun("-td", "--name", id, Image, "sh")
Expect(exitCode).To(Equal(0))
})

AfterEach(func() {
Expect(RemoveDockerContainer(id)).To(BeTrue())
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("check files after a docker cp", func() {
It("should have the corresponding files", func() {
file, err := ioutil.TempFile(os.TempDir(), "file")
Expect(err).ToNot(HaveOccurred())
err = file.Close()
Expect(err).ToNot(HaveOccurred())
defer os.Remove(file.Name())
Expect(file.Name()).To(BeAnExistingFile())

_, _, exitCode = dockerCp(file.Name(), id+":/root/")
Expect(exitCode).To(Equal(0))

stdout, _, exitCode = dockerExec(id, "ls", "/root/")
Expect(exitCode).To(Equal(0))
testFile := path.Base(file.Name())
Expect(stdout).To(ContainSubstring(testFile))
})
})
})
38 changes: 38 additions & 0 deletions integration/docker/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("docker create", func() {
var (
id string
exitCode int
stdout string
)

BeforeEach(func() {
id = randomDockerName()
})

AfterEach(func() {
Expect(RemoveDockerContainer(id)).To(BeTrue())
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("check create functionality", func() {
It("create a container", func() {
_, _, exitCode = dockerCreate("-t", "--name", id, Image)
Expect(exitCode).To(Equal(0))

stdout, _, exitCode = dockerPs("--filter", "status=created")
Expect(exitCode).To(Equal(0))
Expect(stdout).To(ContainSubstring(id))
})
})
})

0 comments on commit 271fa11

Please sign in to comment.