github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_restart_app_instance_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-restart-app-instance Command", func() { 22 var ( 23 cmd V3RestartAppInstanceCommand 24 testUI *ui.UI 25 fakeConfig *commandfakes.FakeConfig 26 fakeSharedActor *commandfakes.FakeSharedActor 27 fakeActor *v6fakes.FakeV3RestartAppInstanceActor 28 binaryName string 29 processType string 30 executeErr error 31 app string 32 ) 33 34 BeforeEach(func() { 35 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 36 fakeConfig = new(commandfakes.FakeConfig) 37 fakeSharedActor = new(commandfakes.FakeSharedActor) 38 fakeActor = new(v6fakes.FakeV3RestartAppInstanceActor) 39 40 binaryName = "faceman" 41 fakeConfig.BinaryNameReturns(binaryName) 42 app = "some-app" 43 processType = "some-special-type" 44 45 cmd = V3RestartAppInstanceCommand{ 46 RequiredArgs: flag.AppInstance{AppName: app, Index: 6}, 47 ProcessType: processType, 48 49 UI: testUI, 50 Config: fakeConfig, 51 SharedActor: fakeSharedActor, 52 Actor: fakeActor, 53 } 54 }) 55 56 JustBeforeEach(func() { 57 executeErr = cmd.Execute(nil) 58 }) 59 60 When("the API version is below the minimum", func() { 61 BeforeEach(func() { 62 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinV3ClientVersion) 63 }) 64 65 It("returns a MinimumAPIVersionNotMetError", func() { 66 Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{ 67 CurrentVersion: ccversion.MinV3ClientVersion, 68 MinimumVersion: ccversion.MinVersionApplicationFlowV3, 69 })) 70 }) 71 72 It("displays the experimental warning", func() { 73 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 74 }) 75 }) 76 77 When("checking target fails", func() { 78 BeforeEach(func() { 79 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 80 fakeSharedActor.CheckTargetReturns(actionerror.NoOrganizationTargetedError{BinaryName: binaryName}) 81 }) 82 83 It("returns an error", func() { 84 Expect(executeErr).To(MatchError(actionerror.NoOrganizationTargetedError{BinaryName: binaryName})) 85 86 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 87 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 88 Expect(checkTargetedOrg).To(BeTrue()) 89 Expect(checkTargetedSpace).To(BeTrue()) 90 }) 91 }) 92 93 When("the user is not logged in", func() { 94 var expectedErr error 95 96 BeforeEach(func() { 97 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 98 expectedErr = errors.New("some current user error") 99 fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) 100 }) 101 102 It("return an error", func() { 103 Expect(executeErr).To(Equal(expectedErr)) 104 }) 105 }) 106 107 When("the user is logged in", func() { 108 BeforeEach(func() { 109 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 110 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 111 Name: "some-org", 112 }) 113 fakeConfig.TargetedSpaceReturns(configv3.Space{ 114 Name: "some-space", 115 GUID: "some-space-guid", 116 }) 117 fakeConfig.CurrentUserReturns(configv3.User{Name: "steve"}, nil) 118 }) 119 120 When("restarting the specified instance returns an error", func() { 121 BeforeEach(func() { 122 fakeActor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndexReturns(v3action.Warnings{"some-warning"}, errors.New("some-error")) 123 }) 124 125 It("displays all warnings and returns the error", func() { 126 Expect(executeErr).To(MatchError("some-error")) 127 128 Expect(testUI.Out).To(Say("Restarting instance 6 of process some-special-type of app some-app in org some-org / space some-space as steve")) 129 Expect(testUI.Err).To(Say("some-warning")) 130 }) 131 }) 132 133 When("restarting the specified instance succeeds", func() { 134 BeforeEach(func() { 135 fakeActor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndexReturns(v3action.Warnings{"some-warning"}, nil) 136 }) 137 138 It("deletes application process instance", func() { 139 Expect(fakeActor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndexCallCount()).To(Equal(1)) 140 appName, spaceGUID, pType, index := fakeActor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndexArgsForCall(0) 141 Expect(appName).To(Equal(app)) 142 Expect(spaceGUID).To(Equal("some-space-guid")) 143 Expect(pType).To(Equal("some-special-type")) 144 Expect(index).To(Equal(6)) 145 }) 146 147 It("displays all warnings and OK", func() { 148 Expect(executeErr).ToNot(HaveOccurred()) 149 150 Expect(testUI.Out).To(Say("Restarting instance 6 of process some-special-type of app some-app in org some-org / space some-space as steve")) 151 Expect(testUI.Out).To(Say("OK")) 152 Expect(testUI.Err).To(Say("some-warning")) 153 }) 154 }) 155 }) 156 })