@@ -27,84 +27,64 @@ import (
2727 "testing"
2828
2929 "github.com/stretchr/testify/assert"
30- "github.com/urfave/cli/v2"
3130 "go.uber.org/mock/gomock"
3231 "go.uber.org/yarpc"
3332
3433 "github.com/uber/cadence/common/types"
3534 "github.com/uber/cadence/tools/cli/clitest"
3635)
3736
38- const testDynamicConfigName = "test-dynamic-config-name"
39-
4037func TestAdminGetDynamicConfig (t * testing.T ) {
4138 tests := []struct {
4239 name string
43- testSetup func (td * cliTestData ) * cli.Context
40+ cmdline string
41+ setupMock func (td * cliTestData )
4442 errContains string // empty if no error is expected
4543 }{
4644 {
47- name : "no arguments provided" ,
48- testSetup : func (td * cliTestData ) * cli.Context {
49- return clitest .NewCLIContext (t , td .app /* arguments are missing */ )
45+ cmdline : `cadence admin config get --name ""` ,
46+ name : "no arguments provided" ,
47+ setupMock : func (td * cliTestData ) {
48+ // empty since arguments are missing
5049 },
5150 errContains : "Required flag not found" ,
5251 },
5352 {
54- name : "failed to get dynamic config values" ,
55- testSetup : func (td * cliTestData ) * cli.Context {
56- cliCtx := clitest .NewCLIContext (
57- t ,
58- td .app ,
59- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
60- )
61-
53+ name : "failed to get dynamic config values" ,
54+ cmdline : `cadence admin config get --name test-dynamic-config-name` ,
55+ setupMock : func (td * cliTestData ) {
6256 td .mockAdminClient .EXPECT ().GetDynamicConfig (gomock .Any (), gomock .Any ()).
6357 DoAndReturn (func (_ context.Context , request * types.GetDynamicConfigRequest , _ ... yarpc.CallOption ) (* types.GetDynamicConfigResponse , error ) {
64- assert .Equal (t , request .ConfigName , testDynamicConfigName )
58+ assert .Equal (t , "test-dynamic-config-name" , request .ConfigName )
6559 return nil , assert .AnError
6660 })
67- return cliCtx
6861 },
6962 errContains : "Failed to get dynamic config value" ,
7063 },
7164 {
72- name : "received a dynamic config value successfully" ,
73- testSetup : func (td * cliTestData ) * cli.Context {
74- cliCtx := clitest .NewCLIContext (
75- t ,
76- td .app ,
77- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
78- )
79-
65+ name : "received a dynamic config value successfully" ,
66+ cmdline : `cadence admin config get --name test-dynamic-config-name` ,
67+ setupMock : func (td * cliTestData ) {
8068 td .mockAdminClient .EXPECT ().GetDynamicConfig (gomock .Any (), gomock .Any ()).
8169 DoAndReturn (func (_ context.Context , request * types.GetDynamicConfigRequest , _ ... yarpc.CallOption ) (* types.GetDynamicConfigResponse , error ) {
82- assert .Equal (t , request .ConfigName , testDynamicConfigName )
70+ assert .Equal (t , "test-dynamic-config-name" , request .ConfigName )
8371 return & types.GetDynamicConfigResponse {
8472 Value : & types.DataBlob {
8573 EncodingType : types .EncodingTypeThriftRW .Ptr (),
8674 Data : []byte (`"config-value"` ),
8775 },
8876 }, nil
8977 })
90- return cliCtx
9178 },
9279 errContains : "" ,
9380 },
9481 {
95- name : "received a dynamic config value with filters successfully" ,
96- testSetup : func (td * cliTestData ) * cli.Context {
97- cliCtx := clitest .NewCLIContext (
98- t ,
99- td .app ,
100- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
101- clitest .StringArgument (FlagDynamicConfigFilter ,
102- `{"domainName":"test-domain", "shardID": 1, "isEnabled": true}` ),
103- )
104-
82+ name : "received a dynamic config value with filters successfully" ,
83+ cmdline : `cadence admin config get --name test-dynamic-config-name --filter '{"domainName":"test-domain", "shardID": 1, "isEnabled": true}'` ,
84+ setupMock : func (td * cliTestData ) {
10585 td .mockAdminClient .EXPECT ().GetDynamicConfig (gomock .Any (), gomock .Any ()).
10686 DoAndReturn (func (_ context.Context , request * types.GetDynamicConfigRequest , _ ... yarpc.CallOption ) (* types.GetDynamicConfigResponse , error ) {
107- assert .Equal (t , request .ConfigName , testDynamicConfigName )
87+ assert .Equal (t , "test-dynamic-config-name" , request .ConfigName )
10888 assert .ElementsMatch (t , request .Filters , []* types.DynamicConfigFilter {
10989 {
11090 Name : "domainName" ,
@@ -135,7 +115,6 @@ func TestAdminGetDynamicConfig(t *testing.T) {
135115 },
136116 }, nil
137117 })
138- return cliCtx
139118 },
140119 errContains : "" ,
141120 },
@@ -144,9 +123,9 @@ func TestAdminGetDynamicConfig(t *testing.T) {
144123 for _ , tt := range tests {
145124 t .Run (tt .name , func (t * testing.T ) {
146125 td := newCLITestData (t )
147- cliCtx := tt .testSetup (td )
126+ tt .setupMock (td )
148127
149- err := AdminGetDynamicConfig ( cliCtx )
128+ err := clitest . RunCommandLine ( t , td . app , tt . cmdline )
150129 if tt .errContains == "" {
151130 assert .NoError (t , err )
152131 } else {
@@ -159,45 +138,31 @@ func TestAdminGetDynamicConfig(t *testing.T) {
159138func TestAdminUpdateDynamicConfig (t * testing.T ) {
160139 tests := []struct {
161140 name string
162- testSetup func (td * cliTestData ) * cli.Context
141+ cmdline string
142+ setupMocks func (td * cliTestData )
163143 errContains string // empty if no error is expected
164144 }{
165145 {
166- name : "no arguments provided" ,
167- testSetup : func (td * cliTestData ) * cli.Context {
168- return clitest .NewCLIContext (t , td .app /* arguments are missing */ )
146+ name : "no arguments provided" ,
147+ cmdline : `cadence admin config update --name "" --value ""` ,
148+ setupMocks : func (td * cliTestData ) {
149+ // empty since arguments are missing
169150 },
170151 errContains : "Required flag not found" ,
171152 },
172153 {
173- name : "calling with required arguments" ,
174- testSetup : func (td * cliTestData ) * cli.Context {
175- cliCtx := clitest .NewCLIContext (
176- t ,
177- td .app ,
178- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
179- clitest .StringArgument (FlagDynamicConfigValue , "'{'Value':some-value,'Filters':[]}'" ),
180- )
181-
154+ name : "calling with required arguments" ,
155+ cmdline : `cadence admin config update --name test-dynamic-config-name --value "{}"` ,
156+ setupMocks : func (td * cliTestData ) {
182157 td .mockAdminClient .EXPECT ().UpdateDynamicConfig (gomock .Any (), gomock .Any ()).Return (nil )
183-
184- return cliCtx
185158 },
186159 errContains : "" ,
187160 },
188161 {
189- name : "failed to update dynamic config values" ,
190- testSetup : func (td * cliTestData ) * cli.Context {
191- cliCtx := clitest .NewCLIContext (
192- t ,
193- td .app ,
194- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
195- clitest .StringArgument (FlagDynamicConfigValue , "'{'Value':some-value,'Filters':[]}'" ),
196- )
197-
162+ name : "failed to update dynamic config values" ,
163+ cmdline : `cadence admin config update --name test-dynamic-config-name --value "{}"` ,
164+ setupMocks : func (td * cliTestData ) {
198165 td .mockAdminClient .EXPECT ().UpdateDynamicConfig (gomock .Any (), gomock .Any ()).Return (assert .AnError )
199-
200- return cliCtx
201166 },
202167 errContains : "Failed to update dynamic config value" ,
203168 },
@@ -206,9 +171,9 @@ func TestAdminUpdateDynamicConfig(t *testing.T) {
206171 for _ , tt := range tests {
207172 t .Run (tt .name , func (t * testing.T ) {
208173 td := newCLITestData (t )
209- cliCtx := tt .testSetup (td )
174+ tt .setupMocks (td )
210175
211- err := AdminUpdateDynamicConfig ( cliCtx )
176+ err := clitest . RunCommandLine ( t , td . app , tt . cmdline )
212177 if tt .errContains == "" {
213178 assert .NoError (t , err )
214179 } else {
@@ -221,45 +186,31 @@ func TestAdminUpdateDynamicConfig(t *testing.T) {
221186func TestAdminRestoreDynamicConfig (t * testing.T ) {
222187 tests := []struct {
223188 name string
224- testSetup func (td * cliTestData ) * cli.Context
189+ cmdline string
190+ setupMocks func (td * cliTestData )
225191 errContains string // empty if no error is expected
226192 }{
227193 {
228- name : "no arguments provided" ,
229- testSetup : func (td * cliTestData ) * cli.Context {
230- return clitest .NewCLIContext (t , td .app /* arguments are missing */ )
194+ name : "no arguments provided" ,
195+ cmdline : `cadence admin config restore --name ''` ,
196+ setupMocks : func (td * cliTestData ) {
197+ // empty since args are missing
231198 },
232199 errContains : "Required flag not found" ,
233200 },
234201 {
235- name : "calling with required arguments" ,
236- testSetup : func (td * cliTestData ) * cli.Context {
237- cliCtx := clitest .NewCLIContext (
238- t ,
239- td .app ,
240- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
241- clitest .StringArgument (FlagDynamicConfigFilter , `{"domainName":"test-domain"}` ),
242- )
243-
202+ name : "calling with required arguments" ,
203+ cmdline : `cadence admin config restore --name test-dynamic-config-name --filter '{"domainName":"test-domain"}'` ,
204+ setupMocks : func (td * cliTestData ) {
244205 td .mockAdminClient .EXPECT ().RestoreDynamicConfig (gomock .Any (), gomock .Any ()).Return (nil )
245-
246- return cliCtx
247206 },
248207 errContains : "" ,
249208 },
250209 {
251- name : "failed to update dynamic config values" ,
252- testSetup : func (td * cliTestData ) * cli.Context {
253- cliCtx := clitest .NewCLIContext (
254- t ,
255- td .app ,
256- clitest .StringArgument (FlagDynamicConfigName , testDynamicConfigName ),
257- clitest .StringArgument (FlagDynamicConfigValue , "'{'Value':some-value,'Filters':[]}'" ),
258- )
259-
210+ name : "failed to update dynamic config values" ,
211+ cmdline : `cadence admin config restore --name test-dynamic-config-name --filter '{"Value":"some-value","Filters":[]}'` ,
212+ setupMocks : func (td * cliTestData ) {
260213 td .mockAdminClient .EXPECT ().RestoreDynamicConfig (gomock .Any (), gomock .Any ()).Return (assert .AnError )
261-
262- return cliCtx
263214 },
264215 errContains : "Failed to restore dynamic config value" ,
265216 },
@@ -268,9 +219,9 @@ func TestAdminRestoreDynamicConfig(t *testing.T) {
268219 for _ , tt := range tests {
269220 t .Run (tt .name , func (t * testing.T ) {
270221 td := newCLITestData (t )
271- cliCtx := tt .testSetup (td )
222+ tt .setupMocks (td )
272223
273- err := AdminRestoreDynamicConfig ( cliCtx )
224+ err := clitest . RunCommandLine ( t , td . app , tt . cmdline )
274225 if tt .errContains == "" {
275226 assert .NoError (t , err )
276227 } else {
@@ -283,49 +234,30 @@ func TestAdminRestoreDynamicConfig(t *testing.T) {
283234func TestAdminListDynamicConfig (t * testing.T ) {
284235 tests := []struct {
285236 name string
286- testSetup func (td * cliTestData ) * cli. Context
237+ setupMocks func (td * cliTestData )
287238 errContains string // empty if no error is expected
288239 }{
289240 {
290241 name : "failed with no dynamic config values stored to list" ,
291- testSetup : func (td * cliTestData ) * cli.Context {
292- cliCtx := clitest .NewCLIContext (
293- t ,
294- td .app ,
295- )
296-
242+ setupMocks : func (td * cliTestData ) {
297243 td .mockAdminClient .EXPECT ().ListDynamicConfig (gomock .Any (), gomock .Any ()).Return (nil , nil )
298-
299- return cliCtx
300244 },
301245 errContains : "" ,
302246 },
303247 {
304248 name : "failed to list dynamic config values" ,
305- testSetup : func (td * cliTestData ) * cli.Context {
306- cliCtx := clitest .NewCLIContext (
307- t ,
308- td .app ,
309- )
310-
249+ setupMocks : func (td * cliTestData ) {
311250 td .mockAdminClient .EXPECT ().ListDynamicConfig (gomock .Any (), gomock .Any ()).Return (nil , assert .AnError )
312-
313- return cliCtx
314251 },
315252 errContains : "Failed to list dynamic config value(s)" ,
316253 },
317254 {
318255 name : "succeeded to list dynamic config values" ,
319- testSetup : func (td * cliTestData ) * cli.Context {
320- cliCtx := clitest .NewCLIContext (
321- t ,
322- td .app ,
323- )
324-
256+ setupMocks : func (td * cliTestData ) {
325257 td .mockAdminClient .EXPECT ().ListDynamicConfig (gomock .Any (), gomock .Any ()).Return (& types.ListDynamicConfigResponse {
326258 Entries : []* types.DynamicConfigEntry {
327259 {
328- Name : testDynamicConfigName ,
260+ Name : "test-dynamic-config-name" ,
329261 Values : []* types.DynamicConfigValue {
330262 {
331263 Value : & types.DataBlob {
@@ -345,8 +277,6 @@ func TestAdminListDynamicConfig(t *testing.T) {
345277 },
346278 },
347279 }}, nil )
348-
349- return cliCtx
350280 },
351281 errContains : "" ,
352282 },
@@ -355,9 +285,9 @@ func TestAdminListDynamicConfig(t *testing.T) {
355285 for _ , tt := range tests {
356286 t .Run (tt .name , func (t * testing.T ) {
357287 td := newCLITestData (t )
358- cliCtx := tt .testSetup (td )
288+ tt .setupMocks (td )
359289
360- err := AdminListDynamicConfig ( cliCtx )
290+ err := clitest . RunCommandLine ( t , td . app , "cadence admin config list" )
361291 if tt .errContains == "" {
362292 assert .NoError (t , err )
363293 } else {
@@ -370,9 +300,6 @@ func TestAdminListDynamicConfig(t *testing.T) {
370300func TestAdminListConfigKeys (t * testing.T ) {
371301 t .Run ("list config keys" , func (t * testing.T ) {
372302 td := newCLITestData (t )
373- cliCtx := clitest .NewCLIContext (t , td .app )
374-
375- err := AdminListConfigKeys (cliCtx )
376- assert .NoError (t , err )
303+ assert .NoError (t , clitest .RunCommandLine (t , td .app , "cadence admin config listall" ))
377304 })
378305}
0 commit comments