github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/create_service_broker_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("create-service-broker command", func() { 14 var ( 15 brokerName string 16 ) 17 18 BeforeEach(func() { 19 // TODO: remove that when capi-release is cut with v3 create-service-broker functionality 20 helpers.SkipIfV7AndVersionLessThan("3.72.0") 21 22 brokerName = helpers.NewServiceBrokerName() 23 24 helpers.LoginCF() 25 }) 26 27 Describe("help", func() { 28 When("--help flag is set", func() { 29 It("displays command usage to output", func() { 30 session := helpers.CF("create-service-broker", "--help") 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("\\s+create-service-broker - Create a service broker")) 33 34 Eventually(session).Should(Say("USAGE:")) 35 Eventually(session).Should(Say("\\s+cf create-service-broker SERVICE_BROKER USERNAME PASSWORD URL \\[--space-scoped\\]")) 36 37 Eventually(session).Should(Say("ALIAS:")) 38 Eventually(session).Should(Say("\\s+csb")) 39 40 Eventually(session).Should(Say("OPTIONS:")) 41 Eventually(session).Should(Say("\\s+--space-scoped Make the broker's service plans only visible within the targeted space")) 42 43 Eventually(session).Should(Say("SEE ALSO:")) 44 Eventually(session).Should(Say("\\s+enable-service-access, service-brokers, target")) 45 46 Eventually(session).Should(Exit(0)) 47 }) 48 }) 49 }) 50 51 When("not logged in", func() { 52 BeforeEach(func() { 53 helpers.LogoutCF() 54 }) 55 56 It("displays an informative error that the user must be logged in", func() { 57 session := helpers.CF("create-service-broker", brokerName, "user", "pass", "http://example.com") 58 Eventually(session).Should(Say("FAILED")) 59 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 60 Eventually(session).Should(Exit(1)) 61 }) 62 }) 63 64 When("logged in", func() { 65 When("all arguments are provided", func() { 66 var ( 67 brokerURI string 68 orgName string 69 spaceName string 70 ) 71 72 BeforeEach(func() { 73 orgName = helpers.NewOrgName() 74 spaceName = helpers.NewSpaceName() 75 76 brokerURI, _ = pushServiceBroker(orgName, spaceName) 77 }) 78 79 When("no org or space is targeted", func() { 80 BeforeEach(func() { 81 helpers.ClearTarget() 82 }) 83 84 AfterEach(func() { 85 Eventually(helpers.CF("delete-service-broker", brokerName, "-f")).Should(Exit(0)) 86 helpers.QuickDeleteOrg(orgName) 87 }) 88 89 It("registers the broker", func() { 90 session := helpers.CF("create-service-broker", brokerName, "username", "password", brokerURI) 91 Eventually(session).Should(Say("Creating service broker %s as admin...", brokerName)) 92 Eventually(session).Should(Say("OK")) 93 Eventually(session).Should(Exit(0)) 94 95 session = helpers.CF("service-brokers") 96 Eventually(session).Should(Say(brokerName)) 97 }) 98 }) 99 100 When("the --space-scoped flag is passed", func() { 101 BeforeEach(func() { 102 // TODO: replace skip with versioned skip when 103 // https://www.pivotaltracker.com/story/show/166063310 is resolved. 104 helpers.SkipIfV7() 105 }) 106 107 When("no org or space is targeted", func() { 108 BeforeEach(func() { 109 helpers.ClearTarget() 110 }) 111 112 It("displays an informative error that a space must be targeted", func() { 113 session := helpers.CF("create-service-broker", "space-scoped-broker", "username", "password", "http://example.com", "--space-scoped") 114 Eventually(session).Should(Say("FAILED")) 115 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 116 Eventually(session).Should(Exit(1)) 117 }) 118 }) 119 120 When("both org and space are targeted", func() { 121 var ( 122 brokerURI string 123 orgName string 124 spaceName string 125 servicePlanName string 126 ) 127 128 BeforeEach(func() { 129 orgName = helpers.NewOrgName() 130 spaceName = helpers.NewSpaceName() 131 brokerURI, servicePlanName = pushServiceBroker(orgName, spaceName) 132 133 helpers.TargetOrgAndSpace(orgName, spaceName) 134 }) 135 136 AfterEach(func() { 137 Eventually(helpers.CF("delete-service-broker", brokerName, "-f")).Should(Exit(0)) 138 helpers.QuickDeleteOrg(orgName) 139 }) 140 141 It("registers the broker and exposes its services only to the targeted space", func() { 142 session := helpers.CF("create-service-broker", brokerName, "username", "password", brokerURI, "--space-scoped") 143 Eventually(session).Should(Say("Creating service broker " + brokerName + " in org " + orgName + " / space " + spaceName + " as admin...")) 144 Eventually(session).Should(Say("OK")) 145 Eventually(session).Should(Exit(0)) 146 147 session = helpers.CF("service-brokers") 148 Eventually(session).Should(Say(brokerName)) 149 150 session = helpers.CF("marketplace") 151 Eventually(session).Should(Say(servicePlanName)) 152 153 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 154 session = helpers.CF("marketplace") 155 Eventually(session).ShouldNot(Say(servicePlanName)) 156 }) 157 }) 158 }) 159 160 When("no arguments are provided", func() { 161 It("displays an error, naming each of the missing args and the help text", func() { 162 session := helpers.CF("create-service-broker") 163 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SERVICE_BROKER`, `USERNAME`, `PASSWORD` and `URL` were not provided")) 164 165 Eventually(session).Should(Say("NAME:")) 166 Eventually(session).Should(Say("\\s+create-service-broker - Create a service broker")) 167 168 Eventually(session).Should(Say("USAGE:")) 169 Eventually(session).Should(Say("\\s+cf create-service-broker SERVICE_BROKER USERNAME PASSWORD URL \\[--space-scoped\\]")) 170 171 Eventually(session).Should(Say("ALIAS:")) 172 Eventually(session).Should(Say("\\s+csb")) 173 174 Eventually(session).Should(Say("OPTIONS:")) 175 Eventually(session).Should(Say("\\s+--space-scoped Make the broker's service plans only visible within the targeted space")) 176 177 Eventually(session).Should(Say("SEE ALSO:")) 178 Eventually(session).Should(Say("\\s+enable-service-access, service-brokers, target")) 179 180 Eventually(session).Should(Exit(1)) 181 }) 182 }) 183 184 When("the broker URL is invalid", func() { 185 BeforeEach(func() { 186 // TODO: replace skip with versioned skip when 187 // https://www.pivotaltracker.com/story/show/166215494 is resolved. 188 helpers.SkipIfV7() 189 }) 190 191 It("displays a relevant error", func() { 192 session := helpers.CF("create-service-broker", brokerName, "user", "pass", "not-a-valid-url") 193 Eventually(session).Should(Say("FAILED")) 194 Eventually(session.Err).Should(Say("not-a-valid-url is not a valid URL")) 195 Eventually(session).Should(Exit(1)) 196 }) 197 }) 198 }) 199 }) 200 }) 201 202 func pushServiceBroker(org, space string) (string, string) { 203 helpers.SetupCF(org, space) 204 205 servicePlanName := helpers.NewPlanName() 206 broker := helpers.NewServiceBroker( 207 helpers.NewServiceBrokerName(), 208 helpers.NewAssets().ServiceBroker, 209 helpers.DefaultSharedDomain(), 210 helpers.PrefixedRandomName("service"), 211 servicePlanName, 212 ) 213 broker.Push() 214 broker.Configure(true) 215 216 return fmt.Sprintf("http://%s.%s", broker.Name, broker.AppsDomain), servicePlanName 217 }