Skip to content

Commit

Permalink
Merge pull request #911 from Pylons-tech/update-test/query_cookbook
Browse files Browse the repository at this point in the history
table test driven for query cookbook
  • Loading branch information
faddat committed Aug 30, 2022
2 parents 4d4a484 + 2927d72 commit 3038461
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions x/pylons/client/cli/query_cookbook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cli_test

import (
"fmt"
"testing"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/stretchr/testify/require"
tmcli "github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

util "github.com/Pylons-tech/pylons/testutil/cli"
"github.com/Pylons-tech/pylons/x/pylons/client/cli"
"github.com/Pylons-tech/pylons/x/pylons/types"
)

func TestShowCookbook(t *testing.T) {
net, cookbook := util.NetworkWithCookbookObjects(t, 2)
ctx := net.Validators[0].ClientCtx

common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
cookbookId string
args []string
err error
obj types.Cookbook
}{
{
desc: "Found",
cookbookId: cookbook[0].Id,
args: common,
obj: cookbook[0],
},
{
desc: "Not found",
cookbookId: "Not found",
args: common,
err: status.Error(codes.InvalidArgument, "not found"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
args := []string{tc.cookbookId}
args = append(args, tc.args...)

out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowCookbook(), args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.QueryGetCookbookResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.Equal(t, tc.obj.Id, resp.Cookbook.Id)

}
})
}
}

0 comments on commit 3038461

Please sign in to comment.