Skip to content

Commit

Permalink
add test cases to avoid decreasing coverage rate
Browse files Browse the repository at this point in the history
  • Loading branch information
torao committed Jun 9, 2022
1 parent 66c3d45 commit fc4087a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
65 changes: 62 additions & 3 deletions cmd/ostracon/commands/show_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sync"
"testing"

"github.com/line/ostracon/types"

cfg "github.com/line/ostracon/config"
"github.com/line/ostracon/crypto"
tmjson "github.com/line/ostracon/libs/json"
Expand Down Expand Up @@ -94,14 +96,71 @@ func TestShowValidatorWithKMS(t *testing.T) {
}

func TestShowValidatorWithInefficientKMSAddress(t *testing.T) {
setupEnv(t)
config := cfg.DefaultConfig()
dir := setupEnv(t)
cfg.EnsureRoot(dir)

original := config
defer func() {
config = original
}()

config = cfg.DefaultConfig()
config.SetRoot(dir)
err := RootCmd.PersistentPreRunE(RootCmd, nil)
require.NoError(t, err)
init := NewInitCmd()
err = init.RunE(init, nil)
require.NoError(t, err)

if tmos.FileExists(config.PrivValidatorKeyFile()) {
err := os.Remove(config.PrivValidatorKeyFile())
require.NoError(t, err)
}
config.PrivValidatorListenAddr = "127.0.0.1:inefficient"
err := showValidator(ShowValidatorCmd, nil, config)
err = showValidator(ShowValidatorCmd, nil, config)
require.Error(t, err)
}

func TestLoadChainID(t *testing.T) {
dir := setupEnv(t)
cfg.EnsureRoot(dir)

original := config
defer func() {
config = original
}()

config = cfg.DefaultConfig()
config.SetRoot(dir)
err := RootCmd.PersistentPreRunE(RootCmd, nil)
require.NoError(t, err)
init := NewInitCmd()
err = init.RunE(init, nil)
require.NoError(t, err)
require.FileExists(t, config.GenesisFile())

genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
require.NoError(t, err)
expected := genDoc.ChainID

chainID, err := loadChainID(config)
require.NoError(t, err)
require.Equal(t, expected, chainID)
}

func TestLoadChainIDWithoutStateDB(t *testing.T) {
dir := setupEnv(t)
config := cfg.DefaultConfig()
config.SetRoot(dir)
err := RootCmd.PersistentPreRunE(RootCmd, nil)
require.NoError(t, err)
init := NewInitCmd()
err = init.RunE(init, nil)
require.NoError(t, err)

config.DBPath = "/../path with containing chars that cannot be used\\/:*?\"<>|\x00"

_, err = loadChainID(config)
require.Error(t, err)
}

Expand Down
12 changes: 12 additions & 0 deletions privval/test_util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package privval

import (
"testing"

"github.com/line/ostracon/crypto"
)

func TestWithMockKMS(t *testing.T) {
dir := t.TempDir()
WithMockKMS(t, dir, "test", func(addr string, privKey crypto.PrivKey) {})
}

0 comments on commit fc4087a

Please sign in to comment.