github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_set_health_check_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/ccv3/constant" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/command/commandfakes" 11 "code.cloudfoundry.org/cli/command/flag" 12 "code.cloudfoundry.org/cli/command/translatableerror" 13 . "code.cloudfoundry.org/cli/command/v6" 14 "code.cloudfoundry.org/cli/command/v6/v6fakes" 15 "code.cloudfoundry.org/cli/util/configv3" 16 "code.cloudfoundry.org/cli/util/ui" 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 . "github.com/onsi/gomega/gbytes" 20 ) 21 22 var _ = Describe("v3-set-health-check Command", func() { 23 var ( 24 cmd V3SetHealthCheckCommand 25 testUI *ui.UI 26 fakeConfig *commandfakes.FakeConfig 27 fakeSharedActor *commandfakes.FakeSharedActor 28 fakeActor *v6fakes.FakeV3SetHealthCheckActor 29 binaryName string 30 executeErr error 31 app string 32 healthCheckType constant.HealthCheckType 33 ) 34 35 BeforeEach(func() { 36 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 37 fakeConfig = new(commandfakes.FakeConfig) 38 fakeSharedActor = new(commandfakes.FakeSharedActor) 39 fakeActor = new(v6fakes.FakeV3SetHealthCheckActor) 40 41 binaryName = "faceman" 42 fakeConfig.BinaryNameReturns(binaryName) 43 app = "some-app" 44 healthCheckType = "some-health-check-type" 45 46 cmd = V3SetHealthCheckCommand{ 47 RequiredArgs: flag.SetHealthCheckArgs{AppName: app, HealthCheck: flag.HealthCheckType{Type: healthCheckType}}, 48 HTTPEndpoint: "some-http-endpoint", 49 ProcessType: "some-process-type", 50 InvocationTimeout: flag.PositiveInteger{Value: 42}, 51 52 UI: testUI, 53 Config: fakeConfig, 54 SharedActor: fakeSharedActor, 55 Actor: fakeActor, 56 } 57 58 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 59 Name: "some-org", 60 GUID: "some-org-guid", 61 }) 62 fakeConfig.TargetedSpaceReturns(configv3.Space{ 63 Name: "some-space", 64 GUID: "some-space-guid", 65 }) 66 67 fakeConfig.CurrentUserReturns(configv3.User{Name: "steve"}, nil) 68 }) 69 70 JustBeforeEach(func() { 71 executeErr = cmd.Execute(nil) 72 }) 73 74 When("the API version is below the minimum", func() { 75 BeforeEach(func() { 76 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinV3ClientVersion) 77 }) 78 79 It("returns a MinimumAPIVersionNotMetError", func() { 80 Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{ 81 CurrentVersion: ccversion.MinV3ClientVersion, 82 MinimumVersion: ccversion.MinVersionApplicationFlowV3, 83 })) 84 }) 85 86 It("displays the experimental warning", func() { 87 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 88 }) 89 }) 90 91 When("checking target fails", func() { 92 BeforeEach(func() { 93 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 94 fakeSharedActor.CheckTargetReturns(actionerror.NoOrganizationTargetedError{BinaryName: binaryName}) 95 }) 96 97 It("returns an error", func() { 98 Expect(executeErr).To(MatchError(actionerror.NoOrganizationTargetedError{BinaryName: binaryName})) 99 100 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 101 102 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 103 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 104 Expect(checkTargetedOrg).To(BeTrue()) 105 Expect(checkTargetedSpace).To(BeTrue()) 106 }) 107 }) 108 109 When("the user is not logged in", func() { 110 var expectedErr error 111 112 BeforeEach(func() { 113 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 114 expectedErr = errors.New("some current user error") 115 fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) 116 }) 117 118 It("return an error", func() { 119 Expect(executeErr).To(Equal(expectedErr)) 120 }) 121 }) 122 123 When("updating the application process health check returns an error", func() { 124 var expectedErr error 125 126 BeforeEach(func() { 127 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 128 expectedErr = actionerror.ApplicationNotFoundError{Name: app} 129 fakeActor.SetApplicationProcessHealthCheckTypeByNameAndSpaceReturns(v3action.Application{}, v3action.Warnings{"warning-1", "warning-2"}, expectedErr) 130 }) 131 132 It("returns the error and prints warnings", func() { 133 Expect(executeErr).To(Equal(actionerror.ApplicationNotFoundError{Name: app})) 134 135 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 136 Expect(testUI.Out).To(Say(`Updating health check type for app some-app process some-process-type in org some-org / space some-space as steve\.\.\.`)) 137 138 Expect(testUI.Err).To(Say("warning-1")) 139 Expect(testUI.Err).To(Say("warning-2")) 140 }) 141 }) 142 143 When("application is started", func() { 144 BeforeEach(func() { 145 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 146 fakeActor.SetApplicationProcessHealthCheckTypeByNameAndSpaceReturns( 147 v3action.Application{ 148 State: constant.ApplicationStarted, 149 }, 150 v3action.Warnings{"warning-1", "warning-2"}, 151 nil) 152 }) 153 154 It("displays a message to restart application", func() { 155 Expect(executeErr).ToNot(HaveOccurred()) 156 157 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 158 Expect(testUI.Out).To(Say(`Updating health check type for app some-app process some-process-type in org some-org / space some-space as steve\.\.\.`)) 159 Expect(testUI.Out).To(Say(`TIP: An app restart is required for the change to take effect\.`)) 160 161 Expect(fakeActor.SetApplicationProcessHealthCheckTypeByNameAndSpaceCallCount()).To(Equal(1)) 162 appName, spaceGUID, healthCheckType, httpEndpoint, processType, invocationTimeout := fakeActor.SetApplicationProcessHealthCheckTypeByNameAndSpaceArgsForCall(0) 163 Expect(appName).To(Equal("some-app")) 164 Expect(spaceGUID).To(Equal("some-space-guid")) 165 Expect(healthCheckType).To(Equal(constant.HealthCheckType("some-health-check-type"))) 166 Expect(httpEndpoint).To(Equal("some-http-endpoint")) 167 Expect(processType).To(Equal("some-process-type")) 168 Expect(invocationTimeout).To(Equal(42)) 169 170 Expect(testUI.Err).To(Say("warning-1")) 171 Expect(testUI.Err).To(Say("warning-2")) 172 }) 173 }) 174 175 When("app is not started", func() { 176 BeforeEach(func() { 177 fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionApplicationFlowV3) 178 fakeActor.SetApplicationProcessHealthCheckTypeByNameAndSpaceReturns( 179 v3action.Application{ 180 State: constant.ApplicationStopped, 181 }, 182 v3action.Warnings{"warning-1", "warning-2"}, 183 nil) 184 }) 185 186 It("does not display a message to restart application", func() { 187 Expect(executeErr).ToNot(HaveOccurred()) 188 189 Expect(testUI.Err).To(Say("This command is in EXPERIMENTAL stage and may change without notice")) 190 Expect(testUI.Out).To(Say(`Updating health check type for app some-app process some-process-type in org some-org / space some-space as steve\.\.\.`)) 191 Expect(testUI.Out).NotTo(Say(`TIP: An app restart is required for the change to take effect\.`)) 192 193 Expect(testUI.Err).To(Say("warning-1")) 194 Expect(testUI.Err).To(Say("warning-2")) 195 }) 196 }) 197 })