From d0941838954e0ce2d8c8849313da2cbdc3a7736d Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Fri, 28 Feb 2020 18:14:01 +0000 Subject: [PATCH 1/2] Increase code coverage of version up to 100% (#5726) --- version/command.go | 41 ++++++++++++++-------------- version/version_test.go | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 version/version_test.go diff --git a/version/command.go b/version/command.go index 9c3b0cfda285..80163db2d47f 100644 --- a/version/command.go +++ b/version/command.go @@ -2,7 +2,6 @@ package version import ( "encoding/json" - "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -21,29 +20,31 @@ func init() { var Cmd = &cobra.Command{ Use: "version", Short: "Print the app version", - RunE: func(_ *cobra.Command, _ []string) error { - verInfo := NewInfo() + RunE: runVersionCmd, +} - if !viper.GetBool(flagLong) { - fmt.Println(verInfo.Version) - return nil - } +func runVersionCmd(cmd *cobra.Command, args []string) error { + verInfo := NewInfo() - var bz []byte - var err error + if !viper.GetBool(flagLong) { + cmd.Println(verInfo.Version) + return nil + } - switch viper.GetString(cli.OutputFlag) { - case "json": - bz, err = json.Marshal(verInfo) - default: - bz, err = yaml.Marshal(&verInfo) - } + var bz []byte + var err error - if err != nil { - return err - } + switch viper.GetString(cli.OutputFlag) { + case "json": + bz, err = json.Marshal(verInfo) + default: + bz, err = yaml.Marshal(&verInfo) + } - _, err = fmt.Println(string(bz)) + if err != nil { return err - }, + } + + cmd.Println(string(bz)) + return nil } diff --git a/version/version_test.go b/version/version_test.go new file mode 100644 index 000000000000..d125b9946907 --- /dev/null +++ b/version/version_test.go @@ -0,0 +1,60 @@ +package version + +import ( + "encoding/json" + "fmt" + "runtime" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/cli" + + "github.com/cosmos/cosmos-sdk/tests" +) + +func TestNewInfo(t *testing.T) { + info := NewInfo() + want := fmt.Sprintf(`: +git commit: +build tags: +%s`, fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)) + require.Equal(t, want, info.String()) +} + +func TestInfo_String(t *testing.T) { + info := Info{ + Name: "testapp", + ServerName: "testappd", + ClientName: "testappcli", + Version: "1.0.0", + GitCommit: "1b78457135a4104bc3af97f20654d49e2ea87454", + BuildTags: "netgo,ledger", + GoVersion: "go version go1.14 linux/amd64", + } + want := fmt.Sprintf(`testapp: 1.0.0 +git commit: 1b78457135a4104bc3af97f20654d49e2ea87454 +build tags: netgo,ledger +go version go1.14 linux/amd64`) + require.Equal(t, want, info.String()) +} + +func Test_runVersionCmd(t *testing.T) { + require.NotNil(t, Cmd) + _, mockOut, _ := tests.ApplyMockIO(Cmd) + + viper.Set(cli.OutputFlag, "") + viper.Set(flagLong, false) + require.NoError(t, runVersionCmd(Cmd, nil)) + assert.Equal(t, "\n", mockOut.String()) + mockOut.Reset() + + viper.Set(cli.OutputFlag, "json") + viper.Set(flagLong, true) + info := NewInfo() + stringInfo, err := json.Marshal(info) + require.NoError(t, err) + require.NoError(t, runVersionCmd(Cmd, nil)) + assert.Equal(t, string(stringInfo)+"\n", mockOut.String()) +} From 7080949f4e3f79c21c445bc3eb3fac99820ca709 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Fri, 28 Feb 2020 18:27:42 +0000 Subject: [PATCH 2/2] Update CODEOWNERS as per @jaekwon's directives (#5728) --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ca82ba88da02..a5519d4ce565 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # CODEOWNERS: https://help.github.com/articles/about-codeowners/ # Primary repo maintainers -* @alexanderbez @jackzampolin @alessio @fedekunze +* @alexanderbez @alessio @fedekunze @nylira @hschoenburg