github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/process_health_check_test.go (about) 1 package v7action_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/actor/v7action/v7actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Process Health Check Actions", func() { 16 var ( 17 actor *Actor 18 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 19 ) 20 21 BeforeEach(func() { 22 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 23 actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil) 24 }) 25 26 Describe("ProcessHealthChecks", func() { 27 var healthchecks ProcessHealthChecks 28 29 BeforeEach(func() { 30 healthchecks = ProcessHealthChecks{ 31 { 32 ProcessType: "worker", 33 HealthCheckType: constant.Process, 34 }, 35 { 36 ProcessType: "console", 37 HealthCheckType: constant.Process, 38 }, 39 { 40 ProcessType: constant.ProcessTypeWeb, 41 HealthCheckType: constant.HTTP, 42 Endpoint: constant.ProcessHealthCheckEndpointDefault, 43 }, 44 } 45 }) 46 47 Describe("Sort", func() { 48 It("sorts healthchecks with web first and then alphabetically sorted", func() { 49 healthchecks.Sort() 50 Expect(healthchecks[0].ProcessType).To(Equal(constant.ProcessTypeWeb)) 51 Expect(healthchecks[1].ProcessType).To(Equal("console")) 52 Expect(healthchecks[2].ProcessType).To(Equal("worker")) 53 }) 54 }) 55 }) 56 57 Describe("GetApplicationProcessHealthChecksByNameAndSpace", func() { 58 var ( 59 warnings Warnings 60 executeErr error 61 processHealthChecks []ProcessHealthCheck 62 ) 63 64 JustBeforeEach(func() { 65 processHealthChecks, warnings, executeErr = actor.GetApplicationProcessHealthChecksByNameAndSpace("some-app-name", "some-space-guid") 66 }) 67 68 When("application does not exist", func() { 69 BeforeEach(func() { 70 fakeCloudControllerClient.GetApplicationsReturns( 71 []ccv3.Application{}, 72 ccv3.Warnings{"some-warning"}, 73 nil, 74 ) 75 }) 76 77 It("returns the error and warnings", func() { 78 Expect(executeErr).To(Equal(actionerror.ApplicationNotFoundError{Name: "some-app-name"})) 79 Expect(warnings).To(ConsistOf("some-warning")) 80 }) 81 }) 82 83 When("getting application returns an error", func() { 84 var expectedErr error 85 86 BeforeEach(func() { 87 expectedErr = errors.New("some-error") 88 fakeCloudControllerClient.GetApplicationsReturns( 89 []ccv3.Application{}, 90 ccv3.Warnings{"some-warning"}, 91 expectedErr, 92 ) 93 }) 94 95 It("returns the error and warnings", func() { 96 Expect(executeErr).To(Equal(expectedErr)) 97 Expect(warnings).To(ConsistOf("some-warning")) 98 }) 99 }) 100 101 When("application exists", func() { 102 BeforeEach(func() { 103 fakeCloudControllerClient.GetApplicationsReturns( 104 []ccv3.Application{ 105 { 106 GUID: "some-app-guid", 107 }, 108 }, 109 ccv3.Warnings{"some-warning"}, 110 nil, 111 ) 112 }) 113 114 When("getting application processes returns an error", func() { 115 var expectedErr error 116 117 BeforeEach(func() { 118 expectedErr = errors.New("some-error") 119 fakeCloudControllerClient.GetApplicationProcessesReturns( 120 []ccv3.Process{}, 121 ccv3.Warnings{"some-process-warning"}, 122 expectedErr, 123 ) 124 }) 125 126 It("returns the error and warnings", func() { 127 Expect(executeErr).To(Equal(expectedErr)) 128 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning")) 129 }) 130 }) 131 132 When("application has processes", func() { 133 BeforeEach(func() { 134 fakeCloudControllerClient.GetApplicationProcessesReturns( 135 []ccv3.Process{ 136 { 137 GUID: "process-guid-1", 138 Type: "process-type-1", 139 HealthCheckType: "health-check-type-1", 140 HealthCheckEndpoint: "health-check-endpoint-1", 141 HealthCheckInvocationTimeout: 42, 142 }, 143 { 144 GUID: "process-guid-2", 145 Type: "process-type-2", 146 HealthCheckType: "health-check-type-2", 147 HealthCheckInvocationTimeout: 0, 148 }, 149 }, 150 ccv3.Warnings{"some-process-warning"}, 151 nil, 152 ) 153 }) 154 155 It("returns health checks", func() { 156 Expect(executeErr).NotTo(HaveOccurred()) 157 Expect(warnings).To(ConsistOf("some-warning", "some-process-warning")) 158 Expect(processHealthChecks).To(Equal([]ProcessHealthCheck{ 159 { 160 ProcessType: "process-type-1", 161 HealthCheckType: "health-check-type-1", 162 Endpoint: "health-check-endpoint-1", 163 InvocationTimeout: 42, 164 }, 165 { 166 ProcessType: "process-type-2", 167 HealthCheckType: "health-check-type-2", 168 InvocationTimeout: 0, 169 }, 170 })) 171 }) 172 }) 173 }) 174 }) 175 })