@@ -79,18 +79,21 @@ func TestSetCmdClientContextHandler(t *testing.T) {
79
79
name string
80
80
expectedContext client.Context
81
81
args []string
82
+ ctx context.Context
82
83
}{
83
84
{
84
85
"no flags set" ,
85
86
initClientCtx ,
86
87
[]string {},
88
+ context .WithValue (context .Background (), client .ClientContextKey , & client.Context {}),
87
89
},
88
90
{
89
91
"flags set" ,
90
92
initClientCtx .WithChainID ("new-chain-id" ),
91
93
[]string {
92
94
fmt .Sprintf ("--%s=new-chain-id" , flags .FlagChainID ),
93
95
},
96
+ context .WithValue (context .Background (), client .ClientContextKey , & client.Context {}),
94
97
},
95
98
{
96
99
"flags set with space" ,
@@ -99,20 +102,37 @@ func TestSetCmdClientContextHandler(t *testing.T) {
99
102
fmt .Sprintf ("--%s" , flags .FlagHome ),
100
103
"/tmp/dir" ,
101
104
},
105
+ context .Background (),
106
+ },
107
+ {
108
+ "no context provided" ,
109
+ initClientCtx .WithHomeDir ("/tmp/noctx" ),
110
+ []string {
111
+ fmt .Sprintf ("--%s" , flags .FlagHome ),
112
+ "/tmp/noctx" ,
113
+ },
114
+ nil ,
115
+ },
116
+ {
117
+ "with invalid client value in the context" ,
118
+ initClientCtx .WithHomeDir ("/tmp/invalid" ),
119
+ []string {
120
+ fmt .Sprintf ("--%s" , flags .FlagHome ),
121
+ "/tmp/invalid" ,
122
+ },
123
+ context .WithValue (context .Background (), client .ClientContextKey , "invalid" ),
102
124
},
103
125
}
104
126
105
127
for _ , tc := range testCases {
106
128
tc := tc
107
129
108
130
t .Run (tc .name , func (t * testing.T ) {
109
- ctx := context .WithValue (context .Background (), client .ClientContextKey , & client.Context {})
110
-
111
131
cmd := newCmd ()
112
132
_ = testutil .ApplyMockIODiscardOutErr (cmd )
113
133
cmd .SetArgs (tc .args )
114
134
115
- require .NoError (t , cmd .ExecuteContext (ctx ))
135
+ require .NoError (t , cmd .ExecuteContext (tc . ctx ))
116
136
117
137
clientCtx := client .GetClientContextFromCmd (cmd )
118
138
require .Equal (t , tc .expectedContext , clientCtx )
0 commit comments