github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_cancel_zdt_push_command_test.go (about) 1 package v6_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v3action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 9 "code.cloudfoundry.org/cli/command/commandfakes" 10 "code.cloudfoundry.org/cli/command/flag" 11 "code.cloudfoundry.org/cli/command/translatableerror" 12 . "code.cloudfoundry.org/cli/command/v6" 13 "code.cloudfoundry.org/cli/command/v6/v6fakes" 14 "code.cloudfoundry.org/cli/util/configv3" 15 "code.cloudfoundry.org/cli/util/ui" 16 . "github.com/onsi/ginkgo" 17 . "github.com/onsi/gomega" 18 . "github.com/onsi/gomega/gbytes" 19 ) 20 21 var _ = Describe("v3-cancel-deployment Command", func() { 22 var ( 23 cmd V3CancelZdtPushCommand 24 testUI *ui.UI 25 fakeConfig *commandfakes.FakeConfig 26 fakeSharedActor *commandfakes.FakeSharedActor 27 fakeV3CancelZdtPushActor *v6fakes.FakeV3CancelZdtPushActor 28 executeErr error 29 app string 30 userName string 31 spaceName string 32 orgName string 33 binaryName string 34 ) 35 36 BeforeEach(func() { 37 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 38 fakeConfig = new(commandfakes.FakeConfig) 39 fakeSharedActor = new(commandfakes.FakeSharedActor) 40 fakeV3CancelZdtPushActor = new(v6fakes.FakeV3CancelZdtPushActor) 41 42 app = "some-app" 43 userName = "banana" 44 spaceName = "some-space" 45 orgName = "some-org" 46 47 cmd = V3CancelZdtPushCommand{ 48 RequiredArgs: flag.AppName{AppName: app}, 49 50 UI: testUI, 51 Config: fakeConfig, 52 CancelZdtPushActor: fakeV3CancelZdtPushActor, 53 SharedActor: fakeSharedActor, 54 } 55 fakeV3CancelZdtPushActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 56 }) 57 58 JustBeforeEach(func() { 59 executeErr = cmd.Execute(nil) 60 }) 61 62 Context("when the API version is below the minimum", func() { 63 BeforeEach(func() { 64 fakeV3CancelZdtPushActor.CloudControllerAPIVersionReturns("0.0.0") 65 }) 66 67 It("returns a MinimumAPIVersionNotMetError", func() { 68 Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{ 69 CurrentVersion: "0.0.0", 70 MinimumVersion: ccversion.MinVersionApplicationFlowV3, 71 })) 72 }) 73 74 It("displays the experimental warning", func() { 75 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 76 }) 77 }) 78 79 When("the user is not logged in", func() { 80 var expectedErr error 81 82 BeforeEach(func() { 83 fakeV3CancelZdtPushActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 84 expectedErr = errors.New("some current user error") 85 fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) 86 }) 87 88 It("return an error", func() { 89 Expect(executeErr).To(Equal(expectedErr)) 90 }) 91 }) 92 93 Context("when checking target fails", func() { 94 BeforeEach(func() { 95 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 96 }) 97 98 It("returns an error", func() { 99 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 100 101 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 102 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 103 Expect(checkTargetedOrg).To(BeTrue()) 104 Expect(checkTargetedSpace).To(BeTrue()) 105 }) 106 }) 107 108 Context("when the user is logged in", func() { 109 BeforeEach(func() { 110 fakeConfig.CurrentUserReturns(configv3.User{Name: userName}, nil) 111 fakeConfig.TargetedSpaceReturns(configv3.Space{Name: spaceName, GUID: "some-space-guid"}) 112 fakeConfig.TargetedOrganizationReturns(configv3.Organization{Name: orgName, GUID: "some-org-guid"}) 113 fakeV3CancelZdtPushActor.CancelDeploymentByAppNameAndSpaceReturns(v3action.Warnings{"get-warning"}, errors.New("some-error")) 114 }) 115 116 It("cancels the deployment", func() { 117 Expect(fakeV3CancelZdtPushActor.CancelDeploymentByAppNameAndSpaceCallCount()).To(Equal(1)) 118 appName, spaceGuid := fakeV3CancelZdtPushActor.CancelDeploymentByAppNameAndSpaceArgsForCall(0) 119 Expect(appName).To(Equal(app)) 120 Expect(spaceGuid).To(Equal("some-space-guid")) 121 122 Expect(executeErr).To(MatchError("some-error")) 123 Expect(testUI.Err).To(Say("get-warning")) 124 }) 125 126 Context("when the application doesn't exist", func() { 127 var expectedErr error 128 129 BeforeEach(func() { 130 expectedErr = errors.New("dropped iphone error") 131 fakeV3CancelZdtPushActor.CancelDeploymentByAppNameAndSpaceReturns(v3action.Warnings{"get-warning"}, expectedErr) 132 }) 133 It("displays the warnings and error", func() { 134 Expect(executeErr).To(MatchError(expectedErr)) 135 136 Expect(testUI.Err).To(Say("get-warning")) 137 Expect(testUI.Out).ToNot(Say("app some-app in org some-org / space some-space as banana...")) 138 }) 139 }) 140 }) 141 })