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