This is an automated email from the ASF dual-hosted git repository. spacewander pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-go-plugin-runner.git
commit b2496e11c5f181a809583f50758f47c6584585b7 Author: spacewander <[email protected]> AuthorDate: Wed May 19 11:45:47 2021 +0800 test: for main's version cmd --- cmd/go-runner/main.go | 9 +++++++-- cmd/go-runner/main_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cmd/go-runner/main.go b/cmd/go-runner/main.go index 38b83be..74851db 100644 --- a/cmd/go-runner/main.go +++ b/cmd/go-runner/main.go @@ -16,6 +16,7 @@ package main import ( "fmt" + "io" "os" "github.com/spf13/cobra" @@ -23,6 +24,10 @@ import ( "github.com/apache/apisix-go-plugin-runner/internal/server" ) +var ( + InfoOut io.Writer = os.Stdout +) + func newVersionCommand() *cobra.Command { var long bool cmd := &cobra.Command{ @@ -30,9 +35,9 @@ func newVersionCommand() *cobra.Command { Short: "version", Run: func(cmd *cobra.Command, _ []string) { if long { - fmt.Print(longVersion()) + fmt.Fprint(InfoOut, longVersion()) } else { - fmt.Printf("version %s\n", shortVersion()) + fmt.Fprintf(InfoOut, "version %s\n", shortVersion()) } }, } diff --git a/cmd/go-runner/main_test.go b/cmd/go-runner/main_test.go new file mode 100644 index 0000000..49d7446 --- /dev/null +++ b/cmd/go-runner/main_test.go @@ -0,0 +1,21 @@ +package main + +import ( + "bytes" + "os" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestVersion(t *testing.T) { + args := []string{"version", "--long"} + os.Args = append([]string{"cmd"}, args...) + + var b bytes.Buffer + InfoOut = &b + main() + + assert.True(t, strings.Contains(b.String(), "Building OS/Arch")) +}
