Skip to content

Commit b868893

Browse files
authored
Merge pull request #3322 from sklarsa/steve/unit-tests
🌱 Adds version command E2E test to improve coverage
2 parents eb8b341 + d60ebab commit b868893

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/cli/cli_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,25 @@ plugins:
464464
)
465465
Expect(err).NotTo(HaveOccurred())
466466
Expect(hasSubCommand(c.cmd, "version")).To(BeTrue())
467+
468+
// Test the version command
469+
c.cmd.SetArgs([]string{"version"})
470+
// Overwrite stdout to read the output and reset it afterwards
471+
r, w, _ := os.Pipe()
472+
temp := os.Stdout
473+
defer func() {
474+
os.Stdout = temp
475+
}()
476+
os.Stdout = w
477+
Expect(c.cmd.Execute()).Should(Succeed())
478+
479+
_ = w.Close()
480+
481+
Expect(err).NotTo(HaveOccurred())
482+
printed, _ := io.ReadAll(r)
483+
Expect(string(printed)).To(Equal(
484+
fmt.Sprintf("%s\n", version)))
485+
467486
})
468487
})
469488

0 commit comments

Comments
 (0)