summaryrefslogtreecommitdiff
path: root/cmd/version_test.go
diff options
context:
space:
mode:
authorMangaal <44372157+Mangaal@users.noreply.github.com>2024-07-02 18:34:26 +0530
committerGitHub <noreply@github.com>2024-07-02 09:04:26 -0400
commit9684b34c64da7e43886cf2ec2586c14f5da6e3b1 (patch)
tree2059f2cf720e3d31b2122d9f45e3f46fc39c8448 /cmd/version_test.go
parentd8d3b018247be19cb4df90230327b0c4bb235c96 (diff)
chore(tests): add unit tests for cmd/template.go, cmd/util.go and cmd/version.go (#765)
Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Diffstat (limited to 'cmd/version_test.go')
-rw-r--r--cmd/version_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/cmd/version_test.go b/cmd/version_test.go
new file mode 100644
index 0000000..76c6532
--- /dev/null
+++ b/cmd/version_test.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/argoproj-labs/argocd-image-updater/pkg/version"
+)
+
+// Helper function to create the expected full version output
+func fullVersionOutput() string {
+ return version.Useragent() + "\n" +
+ " BuildDate: " + version.BuildDate() + "\n" +
+ " GitCommit: " + version.GitCommit() + "\n" +
+ " GoVersion: " + version.GoVersion() + "\n" +
+ " GoCompiler: " + version.GoCompiler() + "\n" +
+ " Platform: " + version.GoPlatform() + "\n"
+}
+
+func TestNewVersionCommand(t *testing.T) {
+ tests := []struct {
+ name string
+ args []string
+ expected string
+ }{
+ {
+ name: "default output",
+ args: []string{},
+ expected: fullVersionOutput(),
+ },
+ {
+ name: "short flag output",
+ args: []string{"--short"},
+ expected: version.Version() + "\n",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cmd := newVersionCommand()
+ buf := new(bytes.Buffer)
+ cmd.SetOut(buf)
+ cmd.SetArgs(tt.args)
+ err := cmd.Execute()
+ assert.NoError(t, err)
+ assert.Equal(t, tt.expected, buf.String())
+ })
+ }
+}