@@ -127,7 +127,6 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
127127
128128func TestContainerListErrors (t * testing.T ) {
129129 testCases := []struct {
130- args []string
131130 flags map [string ]string
132131 containerListFunc func (container.ListOptions ) ([]container.Summary , error )
133132 expectedError string
@@ -157,10 +156,10 @@ func TestContainerListErrors(t *testing.T) {
157156 containerListFunc : tc .containerListFunc ,
158157 }),
159158 )
160- cmd .SetArgs (tc .args )
161159 for key , value := range tc .flags {
162160 assert .Check (t , cmd .Flags ().Set (key , value ))
163161 }
162+ cmd .SetArgs ([]string {})
164163 cmd .SetOut (io .Discard )
165164 cmd .SetErr (io .Discard )
166165 assert .ErrorContains (t , cmd .Execute (), tc .expectedError )
@@ -180,6 +179,9 @@ func TestContainerListWithoutFormat(t *testing.T) {
180179 },
181180 })
182181 cmd := newListCommand (cli )
182+ cmd .SetArgs ([]string {})
183+ cmd .SetOut (io .Discard )
184+ cmd .SetErr (io .Discard )
183185 assert .NilError (t , cmd .Execute ())
184186 golden .Assert (t , cli .OutBuffer ().String (), "container-list-without-format.golden" )
185187}
@@ -194,6 +196,9 @@ func TestContainerListNoTrunc(t *testing.T) {
194196 },
195197 })
196198 cmd := newListCommand (cli )
199+ cmd .SetArgs ([]string {})
200+ cmd .SetOut (io .Discard )
201+ cmd .SetErr (io .Discard )
197202 assert .Check (t , cmd .Flags ().Set ("no-trunc" , "true" ))
198203 assert .NilError (t , cmd .Execute ())
199204 golden .Assert (t , cli .OutBuffer ().String (), "container-list-without-format-no-trunc.golden" )
@@ -210,6 +215,9 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
210215 },
211216 })
212217 cmd := newListCommand (cli )
218+ cmd .SetArgs ([]string {})
219+ cmd .SetOut (io .Discard )
220+ cmd .SetErr (io .Discard )
213221 assert .Check (t , cmd .Flags ().Set ("format" , "{{.Names}} {{.Names}}" ))
214222 assert .NilError (t , cmd .Execute ())
215223 golden .Assert (t , cli .OutBuffer ().String (), "container-list-format-name-name.golden" )
@@ -226,6 +234,9 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
226234 },
227235 })
228236 cmd := newListCommand (cli )
237+ cmd .SetArgs ([]string {})
238+ cmd .SetOut (io .Discard )
239+ cmd .SetErr (io .Discard )
229240 assert .Check (t , cmd .Flags ().Set ("format" , `{{.Names}} {{.Label "some.label"}}` ))
230241 assert .NilError (t , cmd .Execute ())
231242 golden .Assert (t , cli .OutBuffer ().String (), "container-list-format-with-arg.golden" )
@@ -275,6 +286,9 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) {
275286 },
276287 })
277288 cmd := newListCommand (cli )
289+ cmd .SetArgs ([]string {})
290+ cmd .SetOut (io .Discard )
291+ cmd .SetErr (io .Discard )
278292 assert .Check (t , cmd .Flags ().Set ("format" , tc .format ))
279293 if tc .sizeFlag != "" {
280294 assert .Check (t , cmd .Flags ().Set ("size" , tc .sizeFlag ))
@@ -297,6 +311,9 @@ func TestContainerListWithConfigFormat(t *testing.T) {
297311 PsFormat : "{{ .Names }} {{ .Image }} {{ .Labels }} {{ .Size}}" ,
298312 })
299313 cmd := newListCommand (cli )
314+ cmd .SetArgs ([]string {})
315+ cmd .SetOut (io .Discard )
316+ cmd .SetErr (io .Discard )
300317 assert .NilError (t , cmd .Execute ())
301318 golden .Assert (t , cli .OutBuffer ().String (), "container-list-with-config-format.golden" )
302319}
@@ -314,6 +331,9 @@ func TestContainerListWithFormat(t *testing.T) {
314331 t .Run ("with format" , func (t * testing.T ) {
315332 cli .OutBuffer ().Reset ()
316333 cmd := newListCommand (cli )
334+ cmd .SetArgs ([]string {})
335+ cmd .SetOut (io .Discard )
336+ cmd .SetErr (io .Discard )
317337 assert .Check (t , cmd .Flags ().Set ("format" , "{{ .Names }} {{ .Image }} {{ .Labels }}" ))
318338 assert .NilError (t , cmd .Execute ())
319339 golden .Assert (t , cli .OutBuffer ().String (), "container-list-with-format.golden" )
@@ -322,6 +342,9 @@ func TestContainerListWithFormat(t *testing.T) {
322342 t .Run ("with format and quiet" , func (t * testing.T ) {
323343 cli .OutBuffer ().Reset ()
324344 cmd := newListCommand (cli )
345+ cmd .SetArgs ([]string {})
346+ cmd .SetOut (io .Discard )
347+ cmd .SetErr (io .Discard )
325348 assert .Check (t , cmd .Flags ().Set ("format" , "{{ .Names }} {{ .Image }} {{ .Labels }}" ))
326349 assert .Check (t , cmd .Flags ().Set ("quiet" , "true" ))
327350 assert .NilError (t , cmd .Execute ())
0 commit comments