-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff6577a
commit 5f83e02
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} |