Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 3 additions & 40 deletions tests/e2e/crictl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package urunce2etesting

import (
"fmt"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -48,12 +45,7 @@ var _ = Describe("Crictl", Ordered, ContinueOnFailure, func() {

DescribeTable("unikernel containers",
func(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}

skipMissingVolumes(tc)
tool = newCrictlTool(tc)

By("Creating pod")
Expand All @@ -62,7 +54,7 @@ var _ = Describe("Crictl", Ordered, ContinueOnFailure, func() {
tool.setPodID(pID)

DeferCleanup(func() {
if tool != nil && tool.getPodID() != "" {
if tool.getPodID() != "" {
By("Stopping pod")
if err := tool.stopPod(); err != nil {
GinkgoLogr.Error(err, "Failed to stop pod")
Expand All @@ -74,36 +66,7 @@ var _ = Describe("Crictl", Ordered, ContinueOnFailure, func() {
}
})

By("Creating container")
cID, err := tool.createContainer()
Expect(err).NotTo(HaveOccurred(), "Failed to create container: %s", cID)
tool.setContainerID(cID)

DeferCleanup(func() {
if tool != nil && tool.getContainerID() != "" {
By("Stopping container")
if err := tool.stopContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to stop container")
}
By("Removing container")
if err := tool.rmContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to remove container")
}
By("Verifying container removal")
if err := testVerifyRm(tool); err != nil {
GinkgoLogr.Error(err, "Failed to verify removal")
}
}
})

By("Starting container")
output, err := tool.startContainer(true)
Expect(err).NotTo(HaveOccurred(), "Failed to start container: %s", output)

By("Running test function")
Eventually(func() error {
return tc.TestFunc(tool)
}, defaultTimeout, defaultInterval).Should(Succeed())
runDetachedTest(tool, tc)
},
toTableEntries(crictlTestCases()),
)
Expand Down
28 changes: 2 additions & 26 deletions tests/e2e/ctr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package urunce2etesting

import (
"fmt"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -48,30 +45,9 @@ var _ = Describe("Ctr", Ordered, ContinueOnFailure, func() {

DescribeTable("unikernel containers",
func(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}

skipMissingVolumes(tc)
tool = newCtrTool(tc)
tool.setContainerID(tc.Name)

DeferCleanup(func() {
if tool != nil && tool.getContainerID() != "" {
By("Cleaning up container")
if err := testCleanup(tool); err != nil {
GinkgoLogr.Error(err, "Container cleanup failed")
}
}
})

By("Running container")
output, err := tool.runContainer(false)
Expect(err).NotTo(HaveOccurred(), "Failed to run unikernel container: %s", output)

By("Verifying container output")
Expect(output).To(ContainSubstring(tc.ExpectOut))
runForegroundTest(tool, tc)
},
toTableEntries(ctrTestCases()),
)
Expand Down
42 changes: 2 additions & 40 deletions tests/e2e/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package urunce2etesting

import (
"fmt"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -48,44 +45,9 @@ var _ = Describe("Docker", Ordered, ContinueOnFailure, func() {

DescribeTable("unikernel containers",
func(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}

skipMissingVolumes(tc)
tool = newDockerTool(tc)

By("Creating container")
cID, err := tool.createContainer()
Expect(err).NotTo(HaveOccurred(), "Failed to create container: %s", cID)
tool.setContainerID(cID)

DeferCleanup(func() {
if tool != nil && tool.getContainerID() != "" {
By("Stopping container")
if err := tool.stopContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to stop container")
}
By("Removing container")
if err := tool.rmContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to remove container")
}
By("Verifying container removal")
if err := testVerifyRm(tool); err != nil {
GinkgoLogr.Error(err, "Failed to verify removal")
}
}
})

By("Starting container")
output, err := tool.startContainer(true)
Expect(err).NotTo(HaveOccurred(), "Failed to start container: %s", output)

By("Running test function")
Eventually(func() error {
return tc.TestFunc(tool)
}, defaultTimeout, defaultInterval).Should(Succeed())
runDetachedTest(tool, tc)
},
toTableEntries(dockerTestCases()),
)
Expand Down
67 changes: 4 additions & 63 deletions tests/e2e/nerdctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package urunce2etesting

import (
"fmt"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -49,30 +46,9 @@ var _ = Describe("Nerdctl", Ordered, ContinueOnFailure, func() {
Context("foreground containers", func() {
DescribeTable("unikernel containers",
func(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}

skipMissingVolumes(tc)
tool = newNerdctlTool(tc)
tool.setContainerID(tc.Name)

DeferCleanup(func() {
if tool != nil && tool.getContainerID() != "" {
By("Cleaning up container")
if err := testCleanup(tool); err != nil {
GinkgoLogr.Error(err, "Container cleanup failed")
}
}
})

By("Running container")
output, err := tool.runContainer(false)
Expect(err).NotTo(HaveOccurred(), "Failed to run container: %s", output)

By("Verifying container output")
Expect(output).To(ContainSubstring(tc.ExpectOut))
runForegroundTest(tool, tc)
},
toTableEntries(selectTestCases(nerdctlTestCases(), false)),
)
Expand All @@ -81,44 +57,9 @@ var _ = Describe("Nerdctl", Ordered, ContinueOnFailure, func() {
Context("detached containers", func() {
DescribeTable("unikernel containers",
func(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}

skipMissingVolumes(tc)
tool = newNerdctlTool(tc)

By("Creating container")
cID, err := tool.createContainer()
Expect(err).NotTo(HaveOccurred(), "Failed to create container: %s", cID)
tool.setContainerID(cID)

DeferCleanup(func() {
if tool != nil && tool.getContainerID() != "" {
By("Stopping container")
if err := tool.stopContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to stop container")
}
By("Removing container")
if err := tool.rmContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to remove container")
}
By("Verifying container removal")
if err := testVerifyRm(tool); err != nil {
GinkgoLogr.Error(err, "Failed to verify removal")
}
}
})

By("Starting container")
output, err := tool.startContainer(true)
Expect(err).NotTo(HaveOccurred(), "Failed to start container: %s", output)

By("Running test function")
Eventually(func() error {
return tc.TestFunc(tool)
}, defaultTimeout, defaultInterval).Should(Succeed())
runDetachedTest(tool, tc)
},
toTableEntries(selectTestCases(nerdctlTestCases(), true)),
)
Expand Down
67 changes: 67 additions & 0 deletions tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package urunce2etesting

import (
"fmt"
"os"
"testing"
"time"
Expand Down Expand Up @@ -66,3 +67,69 @@ func selectTestCases(cases []containerTestArgs, hasTestFunc bool) []containerTes
}
return out
}

// skipMissingVolumes skips the test if any required volume source is missing.
func skipMissingVolumes(tc containerTestArgs) {
for _, vol := range tc.Volumes {
if _, err := os.Stat(vol.Source); err != nil {
Skip(fmt.Sprintf("Could not find %s", vol.Source))
}
}
}

// runDetachedTest runs a container in detached mode: create, start, and
// verify via TestFunc.
func runDetachedTest(tool testTool, tc containerTestArgs) {
By("Creating container")
cID, err := tool.createContainer()
Expect(err).NotTo(HaveOccurred(), "Failed to create container: %s", cID)
tool.setContainerID(cID)

DeferCleanup(func() {
if tool.getContainerID() != "" {
By("Stopping container")
if err := tool.stopContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to stop container")
}
By("Removing container")
if err := tool.rmContainer(); err != nil {
GinkgoLogr.Error(err, "Failed to remove container")
}
By("Verifying container removal")
if err := testVerifyRm(tool); err != nil {
GinkgoLogr.Error(err, "Failed to verify removal")
}
}
})

By("Starting container")
output, err := tool.startContainer(true)
Expect(err).NotTo(HaveOccurred(), "Failed to start container: %s", output)

By("Running test function")
Eventually(func() error {
return tc.TestFunc(tool)
}, defaultTimeout, defaultInterval).Should(Succeed())
}

// runForegroundTest runs a container in the foreground and verifies the
// output contains the expected string.
func runForegroundTest(tool testTool, tc containerTestArgs) {
tool.setContainerID(tc.Name)

DeferCleanup(func() {
if tool.getContainerID() != "" {
By("Cleaning up container")
if err := testCleanup(tool); err != nil {
GinkgoLogr.Error(err, "Container cleanup failed")
}
}
})

By("Running container")
output, err := tool.runContainer(false)
Expect(err).NotTo(HaveOccurred(), "Failed to run container: %s", output)

By("Verifying container output")
Expect(output).To(ContainSubstring(tc.ExpectOut))
}