github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/enable_service_access_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("enable service access command", func() { 13 Describe("help", func() { 14 matchHelpMessage := SatisfyAll( 15 Say("NAME:"), 16 Say("\\s+enable-service-access - Enable access to a service offering or service plan for one or all orgs"), 17 Say("USAGE:"), 18 Say("\\s+cf enable-service-access SERVICE_OFFERING \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]"), 19 Say("OPTIONS:"), 20 Say("\\s+\\-b\\s+Enable access to a service offering from a particular service broker. Required when service offering name is ambiguous"), 21 Say("\\s+\\-o\\s+Enable access for a specified organization"), 22 Say("\\s+\\-p\\s+Enable access to a specified service plan"), 23 Say("SEE ALSO:"), 24 Say("\\s+disable-service-access, marketplace, service-access, service-brokers"), 25 ) 26 27 When("--help flag is set", func() { 28 It("displays command usage to output", func() { 29 session := helpers.CF("enable-service-access", "--help") 30 Eventually(session).Should(Exit(0)) 31 Expect(session.Out).To(matchHelpMessage) 32 }) 33 }) 34 35 When("no service argument was provided", func() { 36 It("displays a warning, the help text, and exits 1", func() { 37 session := helpers.CF("enable-service-access") 38 Eventually(session).Should(Exit(1)) 39 Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE_OFFERING` was not provided")) 40 Expect(session.Out).To(matchHelpMessage) 41 }) 42 }) 43 44 When("two services arguments are provided", func() { 45 It("displays an error, and exits 1", func() { 46 session := helpers.CF("enable-service-access", "a-service", "another-service") 47 Eventually(session).Should(Exit(1)) 48 Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "another-service"`)) 49 Expect(session.Out).To(Say("FAILED")) 50 Expect(session.Out).To(matchHelpMessage) 51 }) 52 }) 53 }) 54 55 When("logged in", func() { 56 var username string 57 BeforeEach(func() { 58 username, _ = helpers.GetCredentials() 59 helpers.LoginCF() 60 }) 61 62 Context("the service does not exist", func() { 63 It("displays FAILED, an informative error message, and exits 1", func() { 64 session := helpers.CF("enable-service-access", "some-service") 65 Eventually(session).Should(Exit(1)) 66 Expect(session).To(Say("Enabling access to all plans of service offering some-service for all orgs as %s\\.\\.\\.", username)) 67 Expect(session).To(Say("FAILED")) 68 Expect(session.Err).To(Say("Service offering 'some-service' not found")) 69 }) 70 }) 71 72 Context("service offerings exist", func() { 73 var ( 74 orgName string 75 spaceName string 76 serviceOffering string 77 servicePlan string 78 broker *servicebrokerstub.ServiceBrokerStub 79 secondBroker *servicebrokerstub.ServiceBrokerStub 80 ) 81 82 BeforeEach(func() { 83 orgName = helpers.NewOrgName() 84 spaceName = helpers.NewSpaceName() 85 helpers.SetupCF(orgName, spaceName) 86 87 broker = servicebrokerstub.New().WithPlans(2).Create().Register() 88 serviceOffering = broker.FirstServiceOfferingName() 89 servicePlan = broker.FirstServicePlanName() 90 91 session := helpers.CF("service-access", "-e", serviceOffering, "-b", broker.Name) 92 Eventually(session).Should(Exit(0)) 93 Expect(session).To(Say("%s\\s+%s\\s+none", 94 serviceOffering, 95 servicePlan, 96 )) 97 }) 98 99 AfterEach(func() { 100 helpers.QuickDeleteOrg(orgName) 101 broker.Forget() 102 }) 103 104 When("service offering name provided", func() { 105 It("makes all the plans public", func() { 106 session := helpers.CF("enable-service-access", serviceOffering) 107 Eventually(session).Should(Exit(0)) 108 Expect(session).To(Say("Enabling access to all plans of service offering %s for all orgs as %s...", serviceOffering, username)) 109 Expect(session).To(Say("OK")) 110 111 session = helpers.CF("service-access", "-e", serviceOffering) 112 Eventually(session).Should(Exit(0)) 113 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 114 Expect(session).To(Say("%s\\s+%s\\s+all", 115 serviceOffering, 116 servicePlan, 117 )) 118 }) 119 }) 120 121 When("service offering name, plan name and org provided", func() { 122 It("makes the plan public", func() { 123 session := helpers.CF("enable-service-access", serviceOffering, "-p", servicePlan, "-o", orgName, "-v") 124 Eventually(session).Should(Exit(0)) 125 Expect(session).To(Say("Enabling access to plan %s of service offering %s for org %s as %s...", servicePlan, serviceOffering, orgName, username)) 126 Expect(session).To(Say("OK")) 127 128 session = helpers.CF("service-access", "-e", serviceOffering) 129 Eventually(session).Should(Exit(0)) 130 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 131 Expect(session).To(Say("%s\\s+%s\\s+%s\\s+%s", 132 serviceOffering, 133 servicePlan, 134 "limited", 135 orgName, 136 )) 137 }) 138 }) 139 140 When("two services with the same name are registered", func() { 141 BeforeEach(func() { 142 secondBroker = servicebrokerstub.New() 143 secondBroker.Services[0].Name = serviceOffering 144 secondBroker.Services[0].Plans[0].Name = servicePlan 145 secondBroker.Create().Register() 146 }) 147 148 AfterEach(func() { 149 secondBroker.Forget() 150 }) 151 152 When("a serviceOffering name and broker name are provided", func() { 153 It("displays an informative message, exits 0, and enables access to the serviceOffering", func() { 154 session := helpers.CF("enable-service-access", serviceOffering, "-b", secondBroker.Name) 155 Eventually(session).Should(Exit(0)) 156 Expect(session).To(Say("Enabling access to all plans of service offering %s from broker %s for all orgs as %s...", serviceOffering, secondBroker.Name, username)) 157 Expect(session).To(Say("OK")) 158 159 session = helpers.CF("service-access", "-b", secondBroker.Name) 160 Eventually(session).Should(Exit(0)) 161 Expect(session).To(Say("broker:\\s+%s", secondBroker.Name)) 162 Expect(session).To(Say("%s\\s+%s\\s+all", 163 serviceOffering, 164 servicePlan, 165 )) 166 }) 167 }) 168 }) 169 170 Context("when access is already globally enabled", func() { 171 BeforeEach(func() { 172 Eventually(helpers.CF("enable-service-access", serviceOffering)).Should(Exit(0)) 173 }) 174 175 When("when we try to enable access for an org", func() { 176 It("should still be enabled only globally", func() { 177 session := helpers.CF("enable-service-access", serviceOffering, "-o", orgName) 178 Eventually(session).Should(Exit(0)) 179 Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", broker.Services[0].Plans[0].Name)) 180 Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", broker.Services[0].Plans[1].Name)) 181 Expect(session).To(Say("OK")) 182 183 session = helpers.CF("service-access", "-e", serviceOffering) 184 Eventually(session).Should(Exit(0)) 185 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 186 Expect(session).To(Say("%s\\s+%s\\s+all", 187 serviceOffering, 188 servicePlan, 189 )) 190 Expect(string(session.Out.Contents())).NotTo(ContainSubstring(orgName)) 191 }) 192 }) 193 194 When("when we try to enable access for an org for a plan", func() { 195 It("should still be enabled only globally", func() { 196 session := helpers.CF("enable-service-access", serviceOffering, "-o", orgName, "-p", servicePlan) 197 Eventually(session).Should(Exit(0)) 198 Expect(session).To(Say("Did not update plan %s as it already has visibility all\\.", servicePlan)) 199 Expect(session).To(Say("OK")) 200 201 session = helpers.CF("service-access", "-e", serviceOffering) 202 Eventually(session).Should(Exit(0)) 203 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 204 Expect(session).To(Say("%s\\s+%s\\s+all", 205 serviceOffering, 206 servicePlan, 207 )) 208 Expect(string(session.Out.Contents())).NotTo(ContainSubstring(orgName)) 209 }) 210 }) 211 }) 212 }) 213 }) 214 215 Context("not logged in", func() { 216 BeforeEach(func() { 217 helpers.LogoutCF() 218 }) 219 220 It("displays FAILED, an informative error message, and exits 1", func() { 221 session := helpers.CF("enable-service-access", "does-not-matter") 222 Eventually(session).Should(Exit(1)) 223 Expect(session).To(Say("FAILED")) 224 Expect(session.Err).To(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in.")) 225 }) 226 }) 227 228 })