-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/params: CLI Refactor & In-Process Tests (#6720)
ref: #6423
- Loading branch information
1 parent
351192a
commit 44f1482
Showing
3 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package cli_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
tmcli "github.com/tendermint/tendermint/libs/cli" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
"github.com/cosmos/cosmos-sdk/x/params/client/cli" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
s.T().Log("setting up integration test suite") | ||
|
||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 1 | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
||
_, err := s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestNewQuerySubspaceParamsCmd() { | ||
val := s.network.Validators[0] | ||
|
||
testCases := []struct { | ||
name string | ||
args []string | ||
expectedOutput string | ||
}{ | ||
{ | ||
"default output", | ||
[]string{ | ||
"staking", "MaxValidators", | ||
}, | ||
`{"Subspace":"staking","Key":"MaxValidators","Value":"100"}`, | ||
}, | ||
{ | ||
"text output", | ||
[]string{ | ||
"staking", "MaxValidators", | ||
fmt.Sprintf("--%s=text", tmcli.OutputFlag), | ||
}, | ||
`Key: MaxValidators | ||
Subspace: staking | ||
Value: "100"`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(tc.name, func() { | ||
cmd := cli.NewQuerySubspaceParamsCmd() | ||
_, out := testutil.ApplyMockIO(cmd) | ||
|
||
clientCtx := val.ClientCtx.WithOutput(out) | ||
|
||
ctx := context.Background() | ||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx) | ||
|
||
out.Reset() | ||
cmd.SetArgs(tc.args) | ||
|
||
s.Require().NoError(cmd.ExecuteContext(ctx)) | ||
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String())) | ||
}) | ||
} | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters