Skip to content

Commit

Permalink
test with invalid client in the context
Browse files Browse the repository at this point in the history
  • Loading branch information
islishude committed May 12, 2024
1 parent 0f4d04c commit 6847787
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func TestSetCmdClientContextHandler(t *testing.T) {
return c
}

defaultContext := context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})

testCases := []struct {
name string
expectedContext client.Context
Expand All @@ -87,15 +85,15 @@ func TestSetCmdClientContextHandler(t *testing.T) {
"no flags set",
initClientCtx,
[]string{},
defaultContext,
context.WithValue(context.Background(), client.ClientContextKey, &client.Context{}),
},
{
"flags set",
initClientCtx.WithChainID("new-chain-id"),
[]string{
fmt.Sprintf("--%s=new-chain-id", flags.FlagChainID),
},
defaultContext,
context.WithValue(context.Background(), client.ClientContextKey, &client.Context{}),
},
{
"flags set with space",
Expand All @@ -104,7 +102,7 @@ func TestSetCmdClientContextHandler(t *testing.T) {
fmt.Sprintf("--%s", flags.FlagHome),
"/tmp/dir",
},
defaultContext,
context.Background(),
},
{
"no context provided",
Expand All @@ -115,6 +113,15 @@ func TestSetCmdClientContextHandler(t *testing.T) {
},
nil,
},
{
"with invalid client value in the context",
initClientCtx.WithHomeDir("/tmp/invalid"),
[]string{
fmt.Sprintf("--%s", flags.FlagHome),
"/tmp/invalid",
},
context.WithValue(context.Background(), client.ClientContextKey, "invalid"),
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 6847787

Please sign in to comment.