|
5 | 5 | package e2e_test |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "bytes" |
| 9 | + "fmt" |
| 10 | + "os/exec" |
| 11 | + |
8 | 12 | . "github.com/onsi/ginkgo/v2" |
9 | | - _ "github.com/onsi/gomega" |
| 13 | + . "github.com/onsi/gomega" |
10 | 14 | ) |
11 | 15 |
|
| 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 | + |
12 | 37 | var _ = Describe("mgradm tests", func() { |
13 | 38 |
|
| 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 | + }) |
14 | 57 | }) |
0 commit comments