Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
feat: add --version flags
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairruhm committed Dec 2, 2017
1 parent 48637ec commit 7c4363d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ var (

// RootCmd ...
var RootCmd = &cobra.Command{
Use: "zj-db-cluster",
Short: "zijin database cluster command line tool",
Long: ``,
Use: "zj-db-cluster",
Short: "zijin database cluster command line tool",
Long: ``,
Version: VERSION,
Run: func(cmd *cobra.Command, args []string) {
// default command output usage string
cmd.Usage()
Expand Down
4 changes: 2 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### Makefile ---

# https://stackoverflow.com/questions/3931741/why-does-make-think-the-target-is-up-to-date
.PHONY: all test clean


all: build
Expand All @@ -12,12 +15,10 @@ lint:
vendorcheck ./...

test:
go test -v ./...
go test -v -gcflags=-l ./...

clean:
rm -rf bin

integration-test:
go test -tags=integration -v

### Makefile ends here
22 changes: 22 additions & 0 deletions test/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ func TestVersionCmd(t *testing.T) {
})
}

func TestVersionFlags(t *testing.T) {
RootCmd := cmd.RootCmd
Convey("TestVersionCmd", t, func() {
// some global val
Convey("version command should work properly", func() {
buf := new(bytes.Buffer)
RootCmd.SetArgs([]string{"--version"})
RootCmd.SetOutput(buf)

err := RootCmd.Execute()

if err != nil {
t.Error(err)
}

actual := buf.String()
expected := "zj-db-cluster version " + cmd.VERSION + "\n"
So(actual, ShouldEqual, expected)
})
})
}

func TestConfigCmd(t *testing.T) {
rootCmd := cmd.RootCmd
Convey("TestConfigCmd", t, func() {
Expand Down

0 comments on commit 7c4363d

Please sign in to comment.