Skip to content

Commit

Permalink
test: Improve test coverage for additional disk feature (runfinch#280)
Browse files Browse the repository at this point in the history
Issue #, if available:
Improving the e2e test coverage for additional disk.
*Description of changes:*
Adding test to retaining volume, network, and restart the container
after the VM is removed
*Testing done:*



- [x] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Signed-off-by: Ang Zhou <[email protected]>
  • Loading branch information
azhouwd authored Mar 10, 2023
1 parent d4fd1f6 commit b9a94d8
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions e2e/vm/additional_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package vm

import (
"fmt"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/runfinch/common-tests/command"
Expand All @@ -12,32 +14,46 @@ import (

const (
savedImage = "public.ecr.aws/docker/library/alpine:latest"
containerName = "userDataTest"
containerName = "test-ctr"
volumeName = "test-volume"
networkName = "test-network"
)

var testAdditionalDisk = func(o *option.Option) {
ginkgo.Describe("Additional disk", ginkgo.Serial, func() {
ginkgo.It("Retains container user data after the VM is deleted", func() {
command.Run(o, "pull", savedImage)
command.Run(o, "volume", "create", volumeName)
ginkgo.DeferCleanup(command.Run, o, "volume", "rm", volumeName)
command.Run(o, "network", "create", networkName)
ginkgo.DeferCleanup(command.Run, o, "network", "rm", networkName)

command.Run(o, "run", "-d", "--name", containerName, "-v", fmt.Sprintf("%s:/tmp", volumeName),
savedImage, "sh", "-c", "sleep infinity")
command.Run(o, "exec", containerName, "sh", "-c", "echo foo > /tmp/test.txt")
ginkgo.DeferCleanup(command.Run, o, "rmi", savedImage)
oldImagesOutput := command.StdoutStr(o, "images", "--format", "{{.Name}}")
gomega.Expect(oldImagesOutput).Should(gomega.ContainSubstring(savedImage))
ginkgo.DeferCleanup(command.Run, o, "rm", "-f", containerName)

command.Run(o, "run", "--name", containerName, savedImage)
ginkgo.DeferCleanup(command.Run, o, "rm", containerName)
oldPsOutput := command.StdoutStr(o, "ps", "--all", "--format", "{{.Names}}")
gomega.Expect(oldPsOutput).Should(gomega.ContainSubstring(containerName))
command.Run(o, "kill", containerName)

command.New(o, virtualMachineRootCmd, "stop").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
command.Run(o, virtualMachineRootCmd, "remove")

command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(240).Run()

newImagesOutput := command.StdoutStr(o, "images", "--format", "{{.Name}}")
gomega.Expect(newImagesOutput).Should(gomega.Equal(oldImagesOutput))
imageOutput := command.StdoutAsLines(o, "images", "--format", "{{.Name}}")
gomega.Expect(imageOutput).Should(gomega.ContainElement(savedImage))

psOutput := command.StdoutAsLines(o, "ps", "--all", "--format", "{{.Names}}")
gomega.Expect(psOutput).Should(gomega.ContainElement(containerName))

volumeOutput := command.StdoutAsLines(o, "volume", "ls", "--format", "{{.Name}}")
gomega.Expect(volumeOutput).Should(gomega.ContainElement(volumeName))

networkOutput := command.StdoutAsLines(o, "network", "ls", "--format", "{{.Name}}")
gomega.Expect(networkOutput).Should(gomega.ContainElement(networkName))

newPsOutput := command.StdoutStr(o, "ps", "--all", "--format", "{{.Names}}")
gomega.Expect(newPsOutput).Should(gomega.Equal(oldPsOutput))
command.Run(o, "start", containerName)
gomega.Expect(command.StdoutStr(o, "exec", containerName, "cat", "/tmp/test.txt")).
Should(gomega.Equal("foo"))
})
})
}

0 comments on commit b9a94d8

Please sign in to comment.