github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/command/v2/set_health_check_command_test.go (about) 1 package v2_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 "code.cloudfoundry.org/cli/command" 10 "code.cloudfoundry.org/cli/command/commandfakes" 11 "code.cloudfoundry.org/cli/command/v2" 12 "code.cloudfoundry.org/cli/command/v2/v2fakes" 13 "code.cloudfoundry.org/cli/util/configv3" 14 "code.cloudfoundry.org/cli/util/ui" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gbytes" 18 ) 19 20 var _ = Describe("set-health-check Command", func() { 21 var ( 22 cmd v2.SetHealthCheckCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v2fakes.FakeSetHealthCheckActor 27 binaryName string 28 executeErr error 29 ) 30 31 BeforeEach(func() { 32 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 33 fakeConfig = new(commandfakes.FakeConfig) 34 fakeSharedActor = new(commandfakes.FakeSharedActor) 35 fakeActor = new(v2fakes.FakeSetHealthCheckActor) 36 37 cmd = v2.SetHealthCheckCommand{ 38 UI: testUI, 39 Config: fakeConfig, 40 SharedActor: fakeSharedActor, 41 Actor: fakeActor, 42 } 43 44 binaryName = "faceman" 45 fakeConfig.BinaryNameReturns(binaryName) 46 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 47 Name: "some-org", 48 }) 49 fakeConfig.TargetedSpaceReturns(configv3.Space{ 50 GUID: "some-space-guid", 51 Name: "some-space", 52 }) 53 54 fakeConfig.CurrentUserReturns(configv3.User{Name: "some-user"}, nil) 55 }) 56 57 JustBeforeEach(func() { 58 executeErr = cmd.Execute(nil) 59 }) 60 61 Context("when checking the target fails", func() { 62 BeforeEach(func() { 63 fakeSharedActor.CheckTargetReturns( 64 sharedaction.NotLoggedInError{BinaryName: binaryName}) 65 }) 66 67 It("returns an error", func() { 68 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 69 config, targetedOrganizationRequired, targetedSpaceRequired := fakeSharedActor.CheckTargetArgsForCall(0) 70 Expect(config).To(Equal(fakeConfig)) 71 Expect(targetedOrganizationRequired).To(Equal(true)) 72 Expect(targetedSpaceRequired).To(Equal(true)) 73 74 Expect(executeErr).To(MatchError( 75 command.NotLoggedInError{BinaryName: binaryName})) 76 }) 77 }) 78 79 Context("when setting the application health check type returns an error", func() { 80 var expectedErr error 81 82 BeforeEach(func() { 83 cmd.RequiredArgs.AppName = "some-app" 84 cmd.RequiredArgs.HealthCheck.Type = "some-health-check-type" 85 86 expectedErr = errors.New("set health check error") 87 fakeActor.SetApplicationHealthCheckTypeByNameAndSpaceReturns( 88 v2action.Application{}, v2action.Warnings{"warning-1"}, expectedErr) 89 }) 90 91 It("displays warnings and returns the error", func() { 92 Expect(testUI.Err).To(Say("warning-1")) 93 Expect(executeErr).To(MatchError(expectedErr)) 94 }) 95 }) 96 97 Context("when setting health check is successful", func() { 98 BeforeEach(func() { 99 cmd.RequiredArgs.AppName = "some-app" 100 cmd.RequiredArgs.HealthCheck.Type = "some-health-check-type" 101 cmd.HTTPEndpoint = "/" 102 103 fakeActor.SetApplicationHealthCheckTypeByNameAndSpaceReturns( 104 v2action.Application{}, v2action.Warnings{"warning-1"}, nil) 105 }) 106 107 It("informs the user and displays warnings", func() { 108 Expect(testUI.Out).To(Say("Updating health check type for app some-app in org some-org / space some-space as some-user...")) 109 Expect(testUI.Err).To(Say("warning-1")) 110 Expect(testUI.Out).To(Say("OK")) 111 Expect(executeErr).ToNot(HaveOccurred()) 112 113 Expect(fakeActor.SetApplicationHealthCheckTypeByNameAndSpaceCallCount()).To(Equal(1)) 114 name, spaceGUID, healthCheckType, healthCheckHTTPEndpoint := fakeActor.SetApplicationHealthCheckTypeByNameAndSpaceArgsForCall(0) 115 Expect(name).To(Equal("some-app")) 116 Expect(spaceGUID).To(Equal("some-space-guid")) 117 Expect(healthCheckType).To(Equal("some-health-check-type")) 118 Expect(healthCheckHTTPEndpoint).To(Equal("/")) 119 }) 120 }) 121 122 Context("when the app is started", func() { 123 BeforeEach(func() { 124 cmd.RequiredArgs.AppName = "some-app" 125 cmd.RequiredArgs.HealthCheck.Type = "some-health-check-type" 126 127 fakeActor.SetApplicationHealthCheckTypeByNameAndSpaceReturns( 128 v2action.Application{State: ccv2.ApplicationStarted}, v2action.Warnings{"warning-1"}, nil) 129 }) 130 131 It("displays a tip to restart the app", func() { 132 Expect(testUI.Out).To(Say("TIP: An app restart is required for the change to take affect.")) 133 }) 134 }) 135 136 })