Skip to content

Commit 12eb6ed

Browse files
committed
Writting first E2E test
1 parent 459ccd8 commit 12eb6ed

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

.devcontainer/test/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
FROM registry.suse.com/bci/golang:1.21
66

7-
RUN zypper -n install git make curl gcc && zypper clean -a
7+
RUN zypper -n install git make curl gcc podman systemd && zypper clean -a
88
RUN go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.1
99

1010
ENV PATH="/root/go/bin:$PATH"
1111
WORKDIR /workspace
1212

13-
# Default command for debugging or running tests manually
14-
CMD [ "bash" ]
13+
# Indicate to systemd that it's running inside a container.
14+
# This prevents systemd from trying to start all host services.
15+
ENV container docker
16+
17+
# /usr/sbin/init is the standard path for the systemd executable acting as init.
18+
CMD ["/usr/sbin/init"]

tests/e2e/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
. "github.com/onsi/gomega"
1212
)
1313

14-
func TestE2e(t *testing.T) {
14+
func TestE2E(t *testing.T) {
1515
RegisterFailHandler(Fail)
1616
RunSpecs(t, "End-To-End Test Suite")
1717
}

tests/e2e/mgradm_test.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,53 @@
55
package e2e_test
66

77
import (
8+
"bytes"
9+
"fmt"
10+
"os/exec"
11+
812
. "github.com/onsi/ginkgo/v2"
9-
_ "github.com/onsi/gomega"
13+
. "github.com/onsi/gomega"
1014
)
1115

16+
// Define the mgradm binary path
17+
const mgradmPath = "/workspace/bin/mgradm"
18+
19+
// runMgradmCommand is a helper function to execute mgradm and capture its output.
20+
// It returns the combined stdout+stderr and an error if the command fails to run.
21+
func runMgradmCommand(args []string) (string, error) {
22+
cmd := exec.Command(mgradmPath, args...)
23+
24+
var stdoutBuffer bytes.Buffer
25+
var stderrBuffer bytes.Buffer
26+
cmd.Stdout = &stdoutBuffer
27+
cmd.Stderr = &stderrBuffer
28+
29+
By(fmt.Sprintf("Running command: %s %v", mgradmPath, args))
30+
31+
err := cmd.Run()
32+
output := stdoutBuffer.String() + stderrBuffer.String()
33+
34+
return output, err
35+
}
36+
1237
var _ = Describe("mgradm tests", func() {
1338

39+
Context("install command", func() {
40+
It("should run without error with default options", func() {
41+
args := []string{"install", "podman", "--logLevel", "debug"}
42+
output, err := runMgradmCommand(args)
43+
44+
Expect(err).To(Succeed(), "Command failed with error: %v\nOutput: %s", err, output)
45+
Expect(output).To(ContainSubstring("Starting /workspace/bin/mgradm install podman --logLevel debug"))
46+
Expect(output).To(ContainSubstring("Use of this software implies acceptance of the End User License Agreement."))
47+
Expect(output).To(ContainSubstring("application log level=debug"))
48+
})
49+
50+
It("should show help for install command", func() {
51+
args := []string{"install", "--help"}
52+
output, err := runMgradmCommand(args)
53+
Expect(err).To(Succeed())
54+
Expect(output).To(ContainSubstring("Install a new server"))
55+
})
56+
})
1457
})

0 commit comments

Comments
 (0)