github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v7/get_health_check_command_test.go (about) 1 package v7_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 9 "code.cloudfoundry.org/cli/command/commandfakes" 10 "code.cloudfoundry.org/cli/command/flag" 11 . "code.cloudfoundry.org/cli/command/v7" 12 "code.cloudfoundry.org/cli/command/v7/v7fakes" 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("get-health-check Command", func() { 21 var ( 22 cmd GetHealthCheckCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v7fakes.FakeActor 27 binaryName string 28 executeErr error 29 app string 30 ) 31 32 BeforeEach(func() { 33 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 34 fakeConfig = new(commandfakes.FakeConfig) 35 fakeSharedActor = new(commandfakes.FakeSharedActor) 36 fakeActor = new(v7fakes.FakeActor) 37 38 binaryName = "faceman" 39 fakeConfig.BinaryNameReturns(binaryName) 40 app = "some-app" 41 42 cmd = GetHealthCheckCommand{ 43 RequiredArgs: flag.AppName{AppName: app}, 44 45 BaseCommand: BaseCommand{ 46 UI: testUI, 47 Config: fakeConfig, 48 SharedActor: fakeSharedActor, 49 Actor: fakeActor, 50 }, 51 } 52 53 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 54 Name: "some-org", 55 GUID: "some-org-guid", 56 }) 57 fakeConfig.TargetedSpaceReturns(configv3.Space{ 58 Name: "some-space", 59 GUID: "some-space-guid", 60 }) 61 62 fakeConfig.CurrentUserReturns(configv3.User{Name: "steve"}, nil) 63 }) 64 65 JustBeforeEach(func() { 66 executeErr = cmd.Execute(nil) 67 }) 68 69 When("checking target fails", func() { 70 BeforeEach(func() { 71 fakeSharedActor.CheckTargetReturns(actionerror.NoOrganizationTargetedError{BinaryName: binaryName}) 72 }) 73 74 It("returns an error", func() { 75 Expect(executeErr).To(MatchError(actionerror.NoOrganizationTargetedError{BinaryName: binaryName})) 76 77 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 78 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 79 Expect(checkTargetedOrg).To(BeTrue()) 80 Expect(checkTargetedSpace).To(BeTrue()) 81 }) 82 }) 83 84 When("the user is not logged in", func() { 85 var expectedErr error 86 87 BeforeEach(func() { 88 expectedErr = errors.New("some current user error") 89 fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) 90 }) 91 92 It("return an error", func() { 93 Expect(executeErr).To(Equal(expectedErr)) 94 }) 95 }) 96 97 When("getting the application process health checks returns an error", func() { 98 var expectedErr error 99 100 BeforeEach(func() { 101 expectedErr = actionerror.ApplicationNotFoundError{Name: app} 102 fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceReturns(nil, v7action.Warnings{"warning-1", "warning-2"}, expectedErr) 103 }) 104 105 It("returns the error and prints warnings", func() { 106 Expect(executeErr).To(Equal(actionerror.ApplicationNotFoundError{Name: app})) 107 108 Expect(testUI.Out).To(Say("Getting health check type for app some-app in org some-org / space some-space as steve...")) 109 110 Expect(testUI.Err).To(Say("warning-1")) 111 Expect(testUI.Err).To(Say("warning-2")) 112 }) 113 }) 114 115 When("app has no processes", func() { 116 BeforeEach(func() { 117 fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceReturns( 118 []v7action.ProcessHealthCheck{}, 119 v7action.Warnings{"warning-1", "warning-2"}, 120 nil) 121 }) 122 123 It("displays a message that there are no processes", func() { 124 Expect(executeErr).ToNot(HaveOccurred()) 125 126 Expect(testUI.Out).To(Say("Getting health check type for app some-app in org some-org / space some-space as steve...")) 127 Expect(testUI.Out).To(Say("App has no processes")) 128 129 Expect(fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceCallCount()).To(Equal(1)) 130 appName, spaceGUID := fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceArgsForCall(0) 131 Expect(appName).To(Equal("some-app")) 132 Expect(spaceGUID).To(Equal("some-space-guid")) 133 }) 134 }) 135 136 When("app has processes", func() { 137 BeforeEach(func() { 138 appProcessHealthChecks := []v7action.ProcessHealthCheck{ 139 {ProcessType: constant.ProcessTypeWeb, HealthCheckType: constant.HTTP, Endpoint: "/foo", InvocationTimeout: 10}, 140 {ProcessType: "queue", HealthCheckType: constant.Port, Endpoint: "", InvocationTimeout: 0}, 141 {ProcessType: "timer", HealthCheckType: constant.Process, Endpoint: "", InvocationTimeout: 5}, 142 } 143 fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceReturns(appProcessHealthChecks, v7action.Warnings{"warning-1", "warning-2"}, nil) 144 }) 145 146 It("prints the health check type of each process and warnings", func() { 147 Expect(executeErr).ToNot(HaveOccurred()) 148 149 Expect(testUI.Out).To(Say("Getting health check type for app some-app in org some-org / space some-space as steve...")) 150 Expect(testUI.Out).To(Say(`process\s+health check\s+endpoint\s+\(for http\)\s+invocation timeout\n`)) 151 Expect(testUI.Out).To(Say(`web\s+http\s+/foo\s+10\n`)) 152 Expect(testUI.Out).To(Say(`queue\s+port\s+1\n`)) 153 Expect(testUI.Out).To(Say(`timer\s+process\s+5\n`)) 154 155 Expect(fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceCallCount()).To(Equal(1)) 156 appName, spaceGUID := fakeActor.GetApplicationProcessHealthChecksByNameAndSpaceArgsForCall(0) 157 Expect(appName).To(Equal("some-app")) 158 Expect(spaceGUID).To(Equal("some-space-guid")) 159 }) 160 }) 161 })