From e9f1f0cd896c2344349c019a86e98dcd5129a0f5 Mon Sep 17 00:00:00 2001 From: Steve Sklar Date: Sun, 9 Apr 2023 21:15:49 -0400 Subject: [PATCH] adds small version cmd test --- pkg/cli/cli_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index 2e65e80e0da..7503e2cf18b 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -464,6 +464,25 @@ plugins: ) Expect(err).NotTo(HaveOccurred()) Expect(hasSubCommand(c.cmd, "version")).To(BeTrue()) + + // Test the version command + c.cmd.SetArgs([]string{"version"}) + // Overwrite stdout to read the output and reset it afterwards + r, w, _ := os.Pipe() + temp := os.Stdout + defer func() { + os.Stdout = temp + }() + os.Stdout = w + Expect(c.cmd.Execute()).Should(Succeed()) + + _ = w.Close() + + Expect(err).NotTo(HaveOccurred()) + printed, _ := io.ReadAll(r) + Expect(string(printed)).To(Equal( + fmt.Sprintf("%s\n", version))) + }) })