@@ -4,9 +4,10 @@ import (
44 "context"
55 "fmt"
66 "io"
7+ "strings"
78 "testing"
89
9- "github.com/docker/cli/cli/command "
10+ "github.com/docker/cli/cli/streams "
1011 "github.com/docker/cli/internal/test"
1112 "github.com/docker/docker/api/types"
1213 "github.com/docker/docker/api/types/filters"
@@ -94,13 +95,18 @@ func TestNewPruneCommandSuccess(t *testing.T) {
9495 },
9596 }
9697 for _ , tc := range testCases {
97- cli := test .NewFakeCli (& fakeClient {imagesPruneFunc : tc .imagesPruneFunc })
98- cmd := NewPruneCommand (cli )
99- cmd .SetOut (io .Discard )
100- cmd .SetArgs (tc .args )
101- err := cmd .Execute ()
102- assert .NilError (t , err )
103- golden .Assert (t , cli .OutBuffer ().String (), fmt .Sprintf ("prune-command-success.%s.golden" , tc .name ))
98+ t .Run (tc .name , func (t * testing.T ) {
99+ cli := test .NewFakeCli (& fakeClient {imagesPruneFunc : tc .imagesPruneFunc })
100+ // when prompted, answer "Y" to confirm the prune.
101+ // will not be prompted if --force is used.
102+ cli .SetIn (streams .NewIn (io .NopCloser (strings .NewReader ("Y\n " ))))
103+ cmd := NewPruneCommand (cli )
104+ cmd .SetOut (io .Discard )
105+ cmd .SetArgs (tc .args )
106+ err := cmd .Execute ()
107+ assert .NilError (t , err )
108+ golden .Assert (t , cli .OutBuffer ().String (), fmt .Sprintf ("prune-command-success.%s.golden" , tc .name ))
109+ })
104110 }
105111}
106112
@@ -114,8 +120,5 @@ func TestPrunePromptTermination(t *testing.T) {
114120 },
115121 })
116122 cmd := NewPruneCommand (cli )
117- test .TerminatePrompt (ctx , t , cmd , cli , func (t * testing.T , err error ) {
118- t .Helper ()
119- assert .ErrorIs (t , err , command .ErrPromptTerminated )
120- })
123+ test .TerminatePrompt (ctx , t , cmd , cli )
121124}
0 commit comments