forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
64 lines (54 loc) · 1.51 KB
/
version_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package version_test
import (
"encoding/json"
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/version"
)
func TestNewInfo(t *testing.T) {
info := version.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 := version.Info{
Name: "testapp",
AppName: "testappd",
Version: "1.0.0",
GitCommit: "1b78457135a4104bc3af97f20654d49e2ea87454",
BuildTags: "netgo,ledger",
GoVersion: "go version go1.14 linux/amd64",
}
want := `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) {
cmd := version.NewVersionCommand()
_, mockOut := testutil.ApplyMockIO(cmd)
cmd.SetArgs([]string{
fmt.Sprintf("--%s=''", cli.OutputFlag),
"--long=false",
})
require.NoError(t, cmd.Execute())
assert.Equal(t, "\n", mockOut.String())
mockOut.Reset()
cmd.SetArgs([]string{
fmt.Sprintf("--%s=json", cli.OutputFlag), "--long=true",
})
info := version.NewInfo()
stringInfo, err := json.Marshal(info)
require.NoError(t, err)
require.NoError(t, cmd.Execute())
assert.Equal(t, string(stringInfo)+"\n", mockOut.String())
}