1414package e2e
1515
1616import (
17+ "bytes"
18+ "os"
1719 "testing"
1820
1921 "github.com/goharbor/harbor-cli/cmd/harbor/root"
2022 "github.com/goharbor/harbor-cli/pkg/utils"
2123 "github.com/stretchr/testify/assert"
2224)
2325
24- func Test_ConfigCmd (t * testing.T ) {
26+ func Test_ContextCmd (t * testing.T ) {
2527 tempDir := t .TempDir ()
2628 data := Initialize (t , tempDir )
2729 defer ConfigCleanup (t , data )
2830 SetMockKeyring (t )
2931 rootCmd := root .RootCmd ()
30- rootCmd .SetArgs ([]string {"config " })
32+ rootCmd .SetArgs ([]string {"context " })
3133 err := rootCmd .Execute ()
3234 assert .Nil (t , err )
3335}
3436
35- func Test_ConfigListCmd (t * testing.T ) {
37+ func Test_ContextListCmd (t * testing.T ) {
3638 tempDir := t .TempDir ()
3739 data := Initialize (t , tempDir )
3840 defer ConfigCleanup (t , data )
3941 SetMockKeyring (t )
4042 rootCmd := root .RootCmd ()
41- rootCmd .SetArgs ([]string {"config" , "list" })
43+ rootCmd .SetIn (bytes .NewReader (nil ))
44+ os .Setenv ("TTY" , "/dev/null" )
45+ rootCmd .SetArgs ([]string {"context" , "list" })
4246 err := rootCmd .Execute ()
4347 assert .Nil (t , err )
4448}
4549
46- func Test_ConfigGetCmd_Success (t * testing.T ) {
50+ func Test_ContextGetCmd_Success (t * testing.T ) {
4751 tempDir := t .TempDir ()
4852 data := Initialize (t , tempDir )
4953 defer ConfigCleanup (t , data )
@@ -64,12 +68,12 @@ func Test_ConfigGetCmd_Success(t *testing.T) {
6468 t .Fatal (err )
6569 }
6670 rootCmd := root .RootCmd ()
67- rootCmd .SetArgs ([]string {"config " , "get" , "credentials.serveraddress" })
71+ rootCmd .SetArgs ([]string {"context " , "get" , "credentials.serveraddress" })
6872 err = rootCmd .Execute ()
6973 assert .NoError (t , err )
7074}
7175
72- func Test_ConfigGetCmd_Failure (t * testing.T ) {
76+ func Test_ContextGetCmd_Failure (t * testing.T ) {
7377 tempDir := t .TempDir ()
7478 data := Initialize (t , tempDir )
7579 defer ConfigCleanup (t , data )
@@ -90,12 +94,12 @@ func Test_ConfigGetCmd_Failure(t *testing.T) {
9094 t .Fatal (err )
9195 }
9296 rootCmd := root .RootCmd ()
93- rootCmd .SetArgs ([]string {"config " , "get" , "serveraddress" })
97+ rootCmd .SetArgs ([]string {"context " , "get" , "serveraddress" })
9498 err = rootCmd .Execute ()
9599 assert .Error (t , err , "Expected an error when getting a non-existent config item" )
96100}
97101
98- func Test_ConfigGetCmd_CredentialName_Success (t * testing.T ) {
102+ func Test_ContextGetCmd_CredentialName_Success (t * testing.T ) {
99103 tempDir := t .TempDir ()
100104 data := Initialize (t , tempDir )
101105 defer ConfigCleanup (t , data )
@@ -116,12 +120,12 @@ func Test_ConfigGetCmd_CredentialName_Success(t *testing.T) {
116120 t .Fatal (err )
117121 }
118122 rootCmd := root .RootCmd ()
119- rootCmd .SetArgs ([]string {"config " , "get" , "credentials.serveraddress" , "--name" , "harbor-cli@http://demo.goharbor.io" })
123+ rootCmd .SetArgs ([]string {"context " , "get" , "credentials.serveraddress" , "--name" , "harbor-cli@http://demo.goharbor.io" })
120124 err = rootCmd .Execute ()
121125 assert .NoError (t , err )
122126}
123127
124- func Test_ConfigGetCmd_CredentialName_Failure (t * testing.T ) {
128+ func Test_ContextGetCmd_CredentialName_Failure (t * testing.T ) {
125129 tempDir := t .TempDir ()
126130 data := Initialize (t , tempDir )
127131 defer ConfigCleanup (t , data )
@@ -142,12 +146,12 @@ func Test_ConfigGetCmd_CredentialName_Failure(t *testing.T) {
142146 t .Fatal (err )
143147 }
144148 rootCmd := root .RootCmd ()
145- rootCmd .SetArgs ([]string {"config " , "get" , "credentials.serveraddress" , "--name" , "harbor-cli@http://goharbor.io" })
149+ rootCmd .SetArgs ([]string {"context " , "get" , "credentials.serveraddress" , "--name" , "harbor-cli@http://goharbor.io" })
146150 err = rootCmd .Execute ()
147151 assert .Error (t , err , "Expected an error when getting a non-existent credential name" )
148152}
149153
150- func Test_ConfigUpdateCmd_Success (t * testing.T ) {
154+ func Test_ContextUpdateCmd_Success (t * testing.T ) {
151155 tempDir := t .TempDir ()
152156 data := Initialize (t , tempDir )
153157 defer ConfigCleanup (t , data )
@@ -168,12 +172,12 @@ func Test_ConfigUpdateCmd_Success(t *testing.T) {
168172 t .Fatal (err )
169173 }
170174 rootCmd := root .RootCmd ()
171- rootCmd .SetArgs ([]string {"config " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" })
175+ rootCmd .SetArgs ([]string {"context " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" })
172176 err = rootCmd .Execute ()
173177 assert .NoError (t , err )
174178}
175179
176- func Test_ConfigUpdateCmd_CredentialName_Success (t * testing.T ) {
180+ func Test_ContextUpdateCmd_CredentialName_Success (t * testing.T ) {
177181 tempDir := t .TempDir ()
178182 data := Initialize (t , tempDir )
179183 defer ConfigCleanup (t , data )
@@ -194,12 +198,12 @@ func Test_ConfigUpdateCmd_CredentialName_Success(t *testing.T) {
194198 t .Fatal (err )
195199 }
196200 rootCmd := root .RootCmd ()
197- rootCmd .SetArgs ([]string {"config " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" , "--name" , "harbor-cli@http://demo.goharbor.io" })
201+ rootCmd .SetArgs ([]string {"context " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" , "--name" , "harbor-cli@http://demo.goharbor.io" })
198202 err = rootCmd .Execute ()
199203 assert .NoError (t , err )
200204}
201205
202- func Test_ConfigUpdateCmd_CredentialName_Failure (t * testing.T ) {
206+ func Test_ContextUpdateCmd_CredentialName_Failure (t * testing.T ) {
203207 tempDir := t .TempDir ()
204208 data := Initialize (t , tempDir )
205209 defer ConfigCleanup (t , data )
@@ -220,12 +224,12 @@ func Test_ConfigUpdateCmd_CredentialName_Failure(t *testing.T) {
220224 t .Fatal (err )
221225 }
222226 rootCmd := root .RootCmd ()
223- rootCmd .SetArgs ([]string {"config " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" , "--name" , "harbor-cli@http://goharbor.io" })
227+ rootCmd .SetArgs ([]string {"context " , "update" , "credentials.serveraddress" , "http://demo.goharbor.io" , "--name" , "harbor-cli@http://goharbor.io" })
224228 err = rootCmd .Execute ()
225229 assert .Error (t , err , "Expected an error when setting a non-existent credential name" )
226230}
227231
228- func Test_ConfigUpdateCmd_Failure (t * testing.T ) {
232+ func Test_ContextUpdateCmd_Failure (t * testing.T ) {
229233 tempDir := t .TempDir ()
230234 data := Initialize (t , tempDir )
231235 defer ConfigCleanup (t , data )
@@ -246,12 +250,12 @@ func Test_ConfigUpdateCmd_Failure(t *testing.T) {
246250 t .Fatal (err )
247251 }
248252 rootCmd := root .RootCmd ()
249- rootCmd .SetArgs ([]string {"config " , "update" , "serveraddress" , "http://demo.goharbor.io" })
253+ rootCmd .SetArgs ([]string {"context " , "update" , "serveraddress" , "http://demo.goharbor.io" })
250254 err = rootCmd .Execute ()
251255 assert .Error (t , err , "Expected an error when setting a non-existent config item" )
252256}
253257
254- func Test_ConfigDeleteCmd_Success (t * testing.T ) {
258+ func Test_ContextDeleteCmd_Success (t * testing.T ) {
255259 tempDir := t .TempDir ()
256260 data := Initialize (t , tempDir )
257261 defer ConfigCleanup (t , data )
@@ -272,7 +276,7 @@ func Test_ConfigDeleteCmd_Success(t *testing.T) {
272276 t .Fatal (err )
273277 }
274278 rootCmd := root .RootCmd ()
275- rootCmd .SetArgs ([]string {"config " , "delete" , "credentials.serveraddress" })
279+ rootCmd .SetArgs ([]string {"context " , "delete" , "credentials.serveraddress" })
276280 err = rootCmd .Execute ()
277281 assert .NoError (t , err )
278282 config , err := utils .GetCurrentHarborConfig ()
@@ -282,7 +286,7 @@ func Test_ConfigDeleteCmd_Success(t *testing.T) {
282286 assert .Empty (t , config .Credentials [0 ].ServerAddress )
283287}
284288
285- func Test_ConfigDeleteCmd_Failure (t * testing.T ) {
289+ func Test_ContextDeleteCmd_Failure (t * testing.T ) {
286290 tempDir := t .TempDir ()
287291 data := Initialize (t , tempDir )
288292 defer ConfigCleanup (t , data )
@@ -303,12 +307,12 @@ func Test_ConfigDeleteCmd_Failure(t *testing.T) {
303307 t .Fatal (err )
304308 }
305309 rootCmd := root .RootCmd ()
306- rootCmd .SetArgs ([]string {"config " , "delete" , "serveraddress" })
310+ rootCmd .SetArgs ([]string {"context " , "delete" , "serveraddress" })
307311 err = rootCmd .Execute ()
308312 assert .Error (t , err , "Expected an error when deleting a non-existent config item" )
309313}
310314
311- func Test_ConfigDeleteCmd_CredentialName_Success (t * testing.T ) {
315+ func Test_ContextDeleteCmd_CredentialName_Success (t * testing.T ) {
312316 tempDir := t .TempDir ()
313317 data := Initialize (t , tempDir )
314318 defer ConfigCleanup (t , data )
@@ -329,7 +333,7 @@ func Test_ConfigDeleteCmd_CredentialName_Success(t *testing.T) {
329333 t .Fatal (err )
330334 }
331335 rootCmd := root .RootCmd ()
332- rootCmd .SetArgs ([]string {"config " , "delete" , "credentials.serveraddress" , "--name" , "harbor-cli@http://demo.goharbor.io" })
336+ rootCmd .SetArgs ([]string {"context " , "delete" , "credentials.serveraddress" , "--name" , "harbor-cli@http://demo.goharbor.io" })
333337 err = rootCmd .Execute ()
334338 assert .NoError (t , err )
335339 config , err := utils .GetCurrentHarborConfig ()
@@ -339,7 +343,7 @@ func Test_ConfigDeleteCmd_CredentialName_Success(t *testing.T) {
339343 assert .Empty (t , config .Credentials [0 ].ServerAddress )
340344}
341345
342- func Test_ConfigDeleteCmd_CredentialName_Failure (t * testing.T ) {
346+ func Test_ContextDeleteCmd_CredentialName_Failure (t * testing.T ) {
343347 tempDir := t .TempDir ()
344348 data := Initialize (t , tempDir )
345349 defer ConfigCleanup (t , data )
@@ -360,12 +364,12 @@ func Test_ConfigDeleteCmd_CredentialName_Failure(t *testing.T) {
360364 t .Fatal (err )
361365 }
362366 rootCmd := root .RootCmd ()
363- rootCmd .SetArgs ([]string {"config " , "delete" , "credentials.serveraddress" , "--name" , "harbor-cli@http://goharbor.io" })
367+ rootCmd .SetArgs ([]string {"context " , "delete" , "credentials.serveraddress" , "--name" , "harbor-cli@http://goharbor.io" })
364368 err = rootCmd .Execute ()
365369 assert .Error (t , err , "Expected an error when deleting a non-existent credential name" )
366370}
367371
368- func Test_ConfigDeleteCmd_Current_Flag_Success (t * testing.T ) {
372+ func Test_ContextDeleteCmd_Current_Flag_Success (t * testing.T ) {
369373 tempDir := t .TempDir ()
370374 data := Initialize (t , tempDir )
371375 defer ConfigCleanup (t , data )
@@ -392,7 +396,7 @@ func Test_ConfigDeleteCmd_Current_Flag_Success(t *testing.T) {
392396 t .Fatal (err )
393397 }
394398 rootCmd := root .RootCmd ()
395- rootCmd .SetArgs ([]string {"config " , "delete" , "--current" })
399+ rootCmd .SetArgs ([]string {"context " , "delete" , "--current" })
396400 err = rootCmd .Execute ()
397401 assert .NoError (t , err )
398402 config , err := utils .GetCurrentHarborConfig ()
@@ -404,13 +408,13 @@ func Test_ConfigDeleteCmd_Current_Flag_Success(t *testing.T) {
404408 assert .NoError (t , err )
405409}
406410
407- func Test_ConfigDeleteCmd_Current_Flag_With_Item_Failure (t * testing.T ) {
411+ func Test_ContextDeleteCmd_Current_Flag_With_Item_Failure (t * testing.T ) {
408412 tempDir := t .TempDir ()
409413 data := Initialize (t , tempDir )
410414 defer ConfigCleanup (t , data )
411415 SetMockKeyring (t )
412416 rootCmd := root .RootCmd ()
413- rootCmd .SetArgs ([]string {"config " , "delete" , "credentials.serveraddress" , "--current" })
417+ rootCmd .SetArgs ([]string {"context " , "delete" , "credentials.serveraddress" , "--current" })
414418 err := rootCmd .Execute ()
415419 assert .Error (t , err , "Expected an error when specifying both --current and an item" )
416420}
0 commit comments