From a37adb750dde195ed3bb80a5cb661b48e1625ab9 Mon Sep 17 00:00:00 2001 From: Ranjib Dey Date: Wed, 28 Sep 2016 10:05:04 -0700 Subject: [PATCH] Add test. fix version issue --- Makefile | 4 ++++ command/main.go | 14 +++++--------- command/main_test.go | 10 ++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 command/main_test.go diff --git a/Makefile b/Makefile index 35071147..108ccfa8 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,7 @@ build: go get ./... go test ./... go vet ./... + +.PHONY: test +test: + go test ./... diff --git a/command/main.go b/command/main.go index b82c4fc4..7b72ea12 100644 --- a/command/main.go +++ b/command/main.go @@ -7,7 +7,7 @@ import ( ) const ( - version = "0.1" + version = "0.0.0" ) func loadCommands() map[string]cli.CommandFactory { @@ -96,18 +96,14 @@ func loadCommands() map[string]cli.CommandFactory { } func main() { - os.Exit(invokeCLI()) + os.Exit(invokeCLI(os.Args[1:])) } -func invokeCLI() int { - args := os.Args[1:] +func invokeCLI(args []string) int { for _, arg := range args { if arg == "-v" || arg == "--version" { - newArgs := make([]string, len(args)+1) - newArgs[0] = "version" - copy(newArgs[1:], args) - args = newArgs - break + fmt.Println(version) + return 0 } } diff --git a/command/main_test.go b/command/main_test.go new file mode 100644 index 00000000..a0848e95 --- /dev/null +++ b/command/main_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestInvokeCLIVersion(t *testing.T) { + args := []string{"-v"} + if invokeCLI(args) != 0 { + t.Errorf("`pd -v` return code is non zero") + } +}