Skip to content

Commit

Permalink
add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand committed Oct 13, 2020
1 parent ff6577a commit 5f83e02
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

const (
version = "v0.0.1"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show the version of tekton-install",
Long: `Show the version of tekton-install.
# Show version of tekton-install
tekton-install version`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(cmd.OutOrStdout(), version)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
29 changes: 29 additions & 0 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"bytes"
"io/ioutil"
"testing"

"github.com/google/go-cmp/cmp"
)

func Test_version(t *testing.T) {
stdout := bytes.NewBufferString("")
rootCmd.SetOut(stdout)
rootCmd.SetArgs([]string{"version"})
err := rootCmd.Execute()
if err != nil {
t.Fatalf("Error from executing version command: %v", err)
}

out, err := ioutil.ReadAll(stdout)
if err != nil {
t.Fatalf("Error from reading version command stdout: %v", err)
}

expected := version + "\n"
if d := cmp.Diff(string(out), expected); d != "" {
t.Fatalf("-got, +want: %v", d)
}
}
24 changes: 24 additions & 0 deletions test/e2e/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build e2e

package e2e

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func Test_Version_Command(t *testing.T) {
t.Run("Run version command", func(t *testing.T) {
argv := []string{"version"}
output, errMsg := ExecuteCommandOutput(TektonInstallCmd, argv, false)
if errMsg != "" {
t.Log(errMsg)
}

version := "v0.0.1\n"
if d := cmp.Diff(output, version); d != "" {
t.Fatalf("-got, +want: %v", d)
}
})
}

0 comments on commit 5f83e02

Please sign in to comment.