github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/network/disconnect_test.go (about) 1 package network 2 3 import ( 4 "context" 5 "io/ioutil" 6 "testing" 7 8 "github.com/docker/cli/internal/test" 9 "github.com/pkg/errors" 10 "gotest.tools/v3/assert" 11 ) 12 13 func TestNetworkDisconnectErrors(t *testing.T) { 14 testCases := []struct { 15 args []string 16 networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error 17 expectedError string 18 }{ 19 { 20 expectedError: "requires exactly 2 arguments", 21 }, 22 { 23 args: []string{"toto", "titi"}, 24 networkDisconnectFunc: func(ctx context.Context, networkID, container string, force bool) error { 25 return errors.Errorf("error disconnecting network") 26 }, 27 expectedError: "error disconnecting network", 28 }, 29 } 30 31 for _, tc := range testCases { 32 cmd := newDisconnectCommand( 33 test.NewFakeCli(&fakeClient{ 34 networkDisconnectFunc: tc.networkDisconnectFunc, 35 }), 36 ) 37 cmd.SetArgs(tc.args) 38 cmd.SetOut(ioutil.Discard) 39 assert.ErrorContains(t, cmd.Execute(), tc.expectedError) 40 } 41 }