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