@@ -6,10 +6,10 @@ import (
66 "github.com/UpCloudLtd/upcloud-cli/internal/commands"
77 "github.com/UpCloudLtd/upcloud-cli/internal/config"
88 smock "github.com/UpCloudLtd/upcloud-cli/internal/mock"
9+ "github.com/UpCloudLtd/upcloud-cli/internal/mockexecute"
910
1011 "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
1112 "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
12- "github.com/gemalto/flume"
1313 "github.com/stretchr/testify/assert"
1414 "github.com/stretchr/testify/mock"
1515)
@@ -20,29 +20,21 @@ func TestModifyCommand(t *testing.T) {
2020
2121 for _ , test := range []struct {
2222 name string
23- flags []string
24- arg string
23+ args []string
2524 error string
2625 returns * upcloud.Router
2726 req request.ModifyRouterRequest
2827 }{
29- {
30- name : "arg is missing" ,
31- flags : []string {},
32- error : "router is required" ,
33- },
3428 {
3529 name : "name is missing" ,
36- arg : router .UUID ,
37- flags : []string {},
38- error : "name is required" ,
30+ args : []string {router .UUID },
31+ error : `required flag(s) "name" not set` ,
3932 },
4033 {
4134 name : "name is passed" ,
42- arg : router .UUID ,
43- flags : []string {"--name" , "router-2-b" },
35+ args : []string {"--name" , "New name" , router .UUID },
4436 returns : & modifiedRouter ,
45- req : request.ModifyRouterRequest {Name : "router-2-b " , UUID : router .UUID },
37+ req : request.ModifyRouterRequest {Name : "New name " , UUID : router .UUID },
4638 },
4739 } {
4840 targetMethod := "ModifyRouter"
@@ -54,14 +46,14 @@ func TestModifyCommand(t *testing.T) {
5446 conf := config .New ()
5547
5648 c := commands .BuildCommand (ModifyCommand (), nil , conf )
57- if err := c .Cobra ().Flags ().Parse (test .flags ); err != nil {
58- t .Fatal (err )
59- }
60- _ , err := c .(commands.SingleArgumentCommand ).ExecuteSingleArgument (commands .NewExecutor (conf , & mService , flume .New ("test" )), test .arg )
49+
50+ c .Cobra ().SetArgs (test .args )
51+ _ , err := mockexecute .MockExecute (c , & mService , conf )
6152
6253 if test .error != "" {
63- assert .Errorf (t , err , test .error )
54+ assert .EqualError (t , err , test .error )
6455 } else {
56+ assert .NoError (t , err )
6557 mService .AssertNumberOfCalls (t , targetMethod , 1 )
6658 }
6759 })
0 commit comments