refactor: migrate e2e/evidence away from testify suite (#14553)
This commit is contained in:
parent
9742029158
commit
ea26add2a9
@ -4,16 +4,74 @@
|
||||
package evidence
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/simapp"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/client/cli"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
type fixture struct {
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func initFixture(t *testing.T) *fixture {
|
||||
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
|
||||
network, err := network.New(t, t.TempDir(), cfg)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, network.WaitForNextBlock())
|
||||
|
||||
return &fixture{
|
||||
cfg: cfg,
|
||||
network: network,
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetQueryCmd(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
defer f.network.Cleanup()
|
||||
|
||||
val := f.network.Validators[0]
|
||||
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectedOutput string
|
||||
expectErr bool
|
||||
}{
|
||||
"non-existent evidence": {
|
||||
[]string{"DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"},
|
||||
"evidence DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660 not found",
|
||||
true,
|
||||
},
|
||||
"all evidence (default pagination)": {
|
||||
[]string{},
|
||||
"evidence: []\npagination:\n next_key: null\n total: \"0\"",
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
t.Run(name, func(t *testing.T) {
|
||||
cmd := cli.GetQueryCmd()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
assert.Assert(t, err != nil)
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
assert.Assert(t, strings.Contains(strings.TrimSpace(out.String()), tc.expectedOutput))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,76 +0,0 @@
|
||||
package evidence
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/client/cli"
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
|
||||
var err error
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestGetQueryCmd() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := map[string]struct {
|
||||
args []string
|
||||
expectedOutput string
|
||||
expectErr bool
|
||||
}{
|
||||
"non-existent evidence": {
|
||||
[]string{"DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"},
|
||||
"evidence DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660 not found",
|
||||
true,
|
||||
},
|
||||
"all evidence (default pagination)": {
|
||||
[]string{},
|
||||
"evidence: []\npagination:\n next_key: null\n total: \"0\"",
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(name, func() {
|
||||
cmd := cli.GetQueryCmd()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
s.Require().Contains(strings.TrimSpace(out.String()), tc.expectedOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user