11package server
22
33import (
4- "bytes"
54 "testing"
65
76 "github.com/UpCloudLtd/upcloud-cli/internal/commands"
87 "github.com/UpCloudLtd/upcloud-cli/internal/config"
98 smock "github.com/UpCloudLtd/upcloud-cli/internal/mock"
10- "github.com/UpCloudLtd/upcloud-cli/internal/output "
9+ "github.com/UpCloudLtd/upcloud-cli/internal/mockexecute "
1110 internal "github.com/UpCloudLtd/upcloud-cli/internal/service"
1211
1312 "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
1413 "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
15- "github.com/gemalto/flume"
1614 "github.com/jedib0t/go-pretty/v6/text"
1715 "github.com/stretchr/testify/assert"
1816)
@@ -128,7 +126,6 @@ func TestListServers(t *testing.T) {
128126 } {
129127 t .Run (test .name , func (t * testing.T ) {
130128 conf := config .New ()
131- conf .Viper ().Set (config .KeyOutput , config .ValueOutputHuman )
132129
133130 testCmd := ListCommand ()
134131 mService := new (smock.Service )
@@ -138,23 +135,17 @@ func TestListServers(t *testing.T) {
138135 mService .On ("GetServerNetworks" , & request.GetServerNetworksRequest {ServerUUID : uuid }).Return (& serverNetworks , nil )
139136
140137 c := commands .BuildCommand (testCmd , nil , conf )
141- err := c .Cobra ().Flags ().Parse (test .args )
142- assert .NoError (t , err )
143-
144- res , err := c .(commands.NoArgumentCommand ).ExecuteWithoutArguments (commands .NewExecutor (conf , mService , flume .New ("test" )))
145- assert .NoError (t , err )
138+ c .Cobra ().SetArgs (test .args )
146139
147- buf := bytes .NewBuffer (nil )
148- err = output .Render (buf , conf , res )
140+ output , err := mockexecute .MockExecute (c , mService , conf )
149141 assert .NoError (t , err )
150- str := buf .String ()
151142
152143 for _ , contains := range test .outputContains {
153- assert .Contains (t , str , contains )
144+ assert .Contains (t , output , contains )
154145 }
155146
156147 for _ , notContains := range test .outputNotContains {
157- assert .NotContains (t , str , notContains )
148+ assert .NotContains (t , output , notContains )
158149 }
159150 })
160151 }
0 commit comments