github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/handle_health_check_endpoint_override_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "code.cloudfoundry.org/cli/command/translatableerror" 5 "code.cloudfoundry.org/cli/util/manifestparser" 6 7 . "code.cloudfoundry.org/cli/actor/v7pushaction" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("HandleHealthCheckEndpointOverride", func() { 14 var ( 15 originalManifest manifestparser.Manifest 16 transformedManifest manifestparser.Manifest 17 overrides FlagOverrides 18 executeErr error 19 ) 20 21 BeforeEach(func() { 22 originalManifest = manifestparser.Manifest{} 23 overrides = FlagOverrides{} 24 }) 25 26 JustBeforeEach(func() { 27 transformedManifest, executeErr = HandleHealthCheckEndpointOverride(originalManifest, overrides) 28 }) 29 30 When("manifest web process does not specify health check type", func() { 31 BeforeEach(func() { 32 originalManifest.Applications = []manifestparser.Application{ 33 { 34 Processes: []manifestparser.Process{ 35 {Type: "web"}, 36 }, 37 }, 38 } 39 }) 40 41 When("health check type is not set on the flag overrides", func() { 42 It("does not change the manifest", func() { 43 Expect(executeErr).ToNot(HaveOccurred()) 44 Expect(transformedManifest.Applications).To(ConsistOf( 45 manifestparser.Application{ 46 Processes: []manifestparser.Process{ 47 {Type: "web"}, 48 }, 49 }, 50 )) 51 }) 52 }) 53 54 When("health check type set on the flag overrides", func() { 55 BeforeEach(func() { 56 overrides.HealthCheckEndpoint = "/health" 57 }) 58 59 It("changes the health check type of the web process in the manifest", func() { 60 Expect(executeErr).ToNot(HaveOccurred()) 61 Expect(transformedManifest.Applications).To(ConsistOf( 62 manifestparser.Application{ 63 Processes: []manifestparser.Process{ 64 {Type: "web", HealthCheckEndpoint: "/health"}, 65 }, 66 }, 67 )) 68 }) 69 }) 70 }) 71 72 When("health check type flag is set, and manifest app has non-web processes", func() { 73 BeforeEach(func() { 74 overrides.HealthCheckEndpoint = "/health" 75 76 originalManifest.Applications = []manifestparser.Application{ 77 { 78 Processes: []manifestparser.Process{ 79 {Type: "worker", HealthCheckEndpoint: "/health2"}, 80 }, 81 }, 82 } 83 }) 84 85 It("changes the health check type in the app level only", func() { 86 Expect(executeErr).ToNot(HaveOccurred()) 87 Expect(transformedManifest.Applications).To(ConsistOf( 88 manifestparser.Application{ 89 HealthCheckEndpoint: "/health", 90 Processes: []manifestparser.Process{ 91 {Type: "worker", HealthCheckEndpoint: "/health2"}, 92 }, 93 }, 94 )) 95 }) 96 }) 97 98 When("health check type flag is set, and manifest app has web and non-web processes", func() { 99 BeforeEach(func() { 100 overrides.HealthCheckEndpoint = "/health" 101 102 originalManifest.Applications = []manifestparser.Application{ 103 { 104 Processes: []manifestparser.Process{ 105 {Type: "worker", HealthCheckEndpoint: "/health2"}, 106 {Type: "web", HealthCheckEndpoint: "/health3"}, 107 }, 108 HealthCheckEndpoint: "/health2", 109 }, 110 } 111 }) 112 113 It("changes the health check type of the web process in the manifest", func() { 114 Expect(executeErr).ToNot(HaveOccurred()) 115 Expect(transformedManifest.Applications).To(ConsistOf( 116 manifestparser.Application{ 117 HealthCheckEndpoint: "/health2", 118 Processes: []manifestparser.Process{ 119 {Type: "worker", HealthCheckEndpoint: "/health2"}, 120 {Type: "web", HealthCheckEndpoint: "/health"}, 121 }, 122 }, 123 )) 124 }) 125 }) 126 127 When("health check type flag is set and there are multiple apps in the manifest", func() { 128 BeforeEach(func() { 129 overrides.HealthCheckEndpoint = "/health" 130 131 originalManifest.Applications = []manifestparser.Application{ 132 {}, 133 {}, 134 } 135 }) 136 137 It("returns an error", func() { 138 Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{})) 139 }) 140 }) 141 142 When("manifest health check type is not set to http (app level), and health check endpoint flag is set", func() { 143 BeforeEach(func() { 144 overrides.HealthCheckEndpoint = "/health" 145 146 originalManifest.Applications = []manifestparser.Application{ 147 { 148 HealthCheckType: "port", 149 }, 150 } 151 }) 152 153 It("returns an error ", func() { 154 Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{ 155 Arg: "--endpoint", 156 ManifestProperty: "health-check-type", 157 ManifestValue: "port", 158 })) 159 }) 160 }) 161 162 When("manifest health check type is not set to http (process level), and health check endpoint flag is set", func() { 163 BeforeEach(func() { 164 overrides.HealthCheckEndpoint = "/health" 165 166 originalManifest.Applications = []manifestparser.Application{ 167 { 168 Processes: []manifestparser.Process{ 169 {Type: "web", HealthCheckType: "port"}, 170 }, 171 }, 172 } 173 }) 174 175 It("returns an error ", func() { 176 Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{ 177 Arg: "--endpoint", 178 ManifestProperty: "health-check-type", 179 ManifestValue: "port", 180 })) 181 }) 182 }) 183 184 })