github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/plugin/api_test.go (about) 1 package plugin 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("plugin API", func() { 14 Describe("AccessToken", func() { 15 It("returns the access token", func() { 16 confirmTestPluginOutput("AccessToken", "bearer [\\w\\d\\.]+") 17 }) 18 }) 19 20 Describe("ApiEndpoint", func() { 21 It("returns the API endpoint", func() { 22 confirmTestPluginOutput("ApiEndpoint", apiURL) 23 }) 24 }) 25 26 Describe("ApiVersion", func() { 27 It("returns the API version", func() { 28 confirmTestPluginOutput("ApiVersion", "2\\.\\d+\\.\\d+") 29 }) 30 }) 31 32 Describe("CliCommand", func() { 33 It("calls the core cli command and outputs to terminal", func() { 34 confirmTestPluginOutput("CliCommand", "API endpoint", "API endpoint") 35 }) 36 }) 37 38 Describe("CliCommandWithoutTerminalOutput", func() { 39 It("calls the core cli command and without outputting to the terminal", func() { 40 session := helpers.CF("CliCommandWithoutTerminalOutput", "target") 41 Eventually(session).Should(Say("API endpoint")) 42 Consistently(session).ShouldNot(Say("API endpoint")) 43 Eventually(session).Should(Exit(0)) 44 }) 45 }) 46 47 Describe("DopplerEndpoint", func() { 48 It("gets Doppler Endpoint", func() { 49 confirmTestPluginOutput("DopplerEndpoint", "wss://doppler") 50 }) 51 }) 52 53 Describe("GetApp", func() { 54 var appName string 55 BeforeEach(func() { 56 createTargetedOrgAndSpace() 57 appName = helpers.PrefixedRandomName("APP") 58 helpers.WithHelloWorldApp(func(appDir string) { 59 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 60 }) 61 }) 62 63 It("gets application information", func() { 64 confirmTestPluginOutputWithArg("GetApp", appName, appName) 65 }) 66 }) 67 68 Describe("GetApps", func() { 69 var appName1, appName2 string 70 BeforeEach(func() { 71 createTargetedOrgAndSpace() 72 appName1 = helpers.PrefixedRandomName("APP") 73 helpers.WithHelloWorldApp(func(appDir string) { 74 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 75 }) 76 appName2 = helpers.PrefixedRandomName("APP") 77 helpers.WithHelloWorldApp(func(appDir string) { 78 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 79 }) 80 }) 81 82 It("gets information for multiple applications", func() { 83 appNameRegexp := fmt.Sprintf("(?:%s|%s)", appName1, appName2) 84 confirmTestPluginOutput("GetApps", appNameRegexp, appNameRegexp) 85 }) 86 }) 87 88 Describe("GetCurrentOrg", func() { 89 It("gets the current targeted org", func() { 90 org, _ := createTargetedOrgAndSpace() 91 confirmTestPluginOutput("GetCurrentOrg", org) 92 }) 93 }) 94 95 Describe("GetCurrentSpace", func() { 96 It("gets the current targeted Space", func() { 97 _, space := createTargetedOrgAndSpace() 98 confirmTestPluginOutput("GetCurrentSpace", space) 99 }) 100 }) 101 102 Describe("GetOrg", func() { 103 It("gets the given org", func() { 104 org, _ := createTargetedOrgAndSpace() 105 confirmTestPluginOutputWithArg("GetOrg", org, org) 106 }) 107 }) 108 109 Describe("GetOrgs", func() { 110 It("gets information for multiple orgs", func() { 111 org1, _ := createTargetedOrgAndSpace() 112 org2, _ := createTargetedOrgAndSpace() 113 orgNameRegexp := fmt.Sprintf("(?:%s|%s)", org1, org2) 114 confirmTestPluginOutput("GetOrgs", orgNameRegexp, orgNameRegexp) 115 }) 116 }) 117 118 Describe("GetOrgUsers", func() { 119 It("returns the org users", func() { 120 org, _ := createTargetedOrgAndSpace() 121 username, _ := helpers.GetCredentials() 122 confirmTestPluginOutputWithArg("GetOrgUsers", org, username) 123 }) 124 }) 125 126 Describe("GetOrgUsers", func() { 127 It("returns the org users", func() { 128 org, _ := createTargetedOrgAndSpace() 129 username, _ := helpers.GetCredentials() 130 confirmTestPluginOutputWithArg("GetOrgUsers", org, username) 131 }) 132 }) 133 134 Describe("GetService", func() { 135 var ( 136 serviceInstance string 137 broker helpers.ServiceBroker 138 ) 139 BeforeEach(func() { 140 createTargetedOrgAndSpace() 141 domain := defaultSharedDomain() 142 service := helpers.PrefixedRandomName("SERVICE") 143 servicePlan := helpers.PrefixedRandomName("SERVICE-PLAN") 144 serviceInstance = helpers.PrefixedRandomName("SI") 145 broker = helpers.NewServiceBroker(helpers.PrefixedRandomName("SERVICE-BROKER"), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 146 broker.Push() 147 broker.Configure() 148 broker.Create() 149 150 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 151 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 152 }) 153 154 AfterEach(func() { 155 broker.Destroy() 156 }) 157 158 It("gets the given service instance", func() { 159 confirmTestPluginOutputWithArg("GetService", serviceInstance, serviceInstance) 160 }) 161 }) 162 163 Describe("GetServices", func() { 164 var ( 165 serviceInstance1 string 166 serviceInstance2 string 167 broker helpers.ServiceBroker 168 ) 169 BeforeEach(func() { 170 createTargetedOrgAndSpace() 171 domain := defaultSharedDomain() 172 service := helpers.PrefixedRandomName("SERVICE") 173 servicePlan := helpers.PrefixedRandomName("SERVICE-PLAN") 174 serviceInstance1 = helpers.PrefixedRandomName("SI1") 175 serviceInstance2 = helpers.PrefixedRandomName("SI2") 176 broker = helpers.NewServiceBroker(helpers.PrefixedRandomName("SERVICE-BROKER"), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 177 broker.Push() 178 broker.Configure() 179 broker.Create() 180 181 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 182 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance1)).Should(Exit(0)) 183 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance2)).Should(Exit(0)) 184 }) 185 186 AfterEach(func() { 187 broker.Destroy() 188 }) 189 190 It("returns a list of services instances", func() { 191 servicesNameRegexp := fmt.Sprintf("(?:%s|%s)", serviceInstance1, serviceInstance2) 192 confirmTestPluginOutput("GetServices", servicesNameRegexp, servicesNameRegexp) 193 }) 194 }) 195 196 Describe("GetSpace", func() { 197 It("gets the given space", func() { 198 _, space := createTargetedOrgAndSpace() 199 confirmTestPluginOutputWithArg("GetSpace", space, space) 200 }) 201 }) 202 203 Describe("GetSpaces", func() { 204 var space1, space2 string 205 206 BeforeEach(func() { 207 _, space1 = createTargetedOrgAndSpace() 208 space2 = helpers.PrefixedRandomName("SPACE") 209 helpers.CreateSpace(space2) 210 }) 211 212 It("gets information for multiple spaces", func() { 213 spaceNameRegexp := fmt.Sprintf("(?:%s|%s)", space1, space2) 214 confirmTestPluginOutput("GetSpaces", spaceNameRegexp, spaceNameRegexp) 215 }) 216 }) 217 218 Describe("GetSpaceUsers", func() { 219 It("returns the space users", func() { 220 org, space := createTargetedOrgAndSpace() 221 username, _ := helpers.GetCredentials() 222 session := helpers.CF("GetSpaceUsers", org, space) 223 Eventually(session).Should(Say(username)) 224 Eventually(session).Should(Exit(0)) 225 }) 226 }) 227 228 Describe("HasAPIEndpoint", func() { 229 It("returns true", func() { 230 confirmTestPluginOutput("HasAPIEndpoint", "true") 231 }) 232 }) 233 234 Describe("HasOrganization", func() { 235 It("returns true", func() { 236 createTargetedOrgAndSpace() 237 confirmTestPluginOutput("HasOrganization", "true") 238 }) 239 }) 240 241 Describe("HasSpace", func() { 242 It("returns true", func() { 243 createTargetedOrgAndSpace() 244 confirmTestPluginOutput("HasSpace", "true") 245 }) 246 }) 247 248 Describe("IsLoggedIn", func() { 249 It("returns a true", func() { 250 confirmTestPluginOutput("IsLoggedIn", "true") 251 }) 252 }) 253 254 Describe("IsSSLDisabled", func() { 255 It("returns a true or false", func() { 256 if skipSSLValidation == "" { 257 confirmTestPluginOutput("IsSSLDisabled", "false") 258 } else { 259 confirmTestPluginOutput("IsSSLDisabled", "true") 260 } 261 }) 262 }) 263 264 Describe("LoggregatorEndpoint", func() { 265 It("gets Loggregator Endpoint", func() { 266 confirmTestPluginOutput("LoggregatorEndpoint", "") 267 }) 268 }) 269 270 Describe("UserEmail", func() { 271 It("gets the current user's Email", func() { 272 username, _ := helpers.GetCredentials() 273 confirmTestPluginOutput("UserEmail", username) 274 }) 275 }) 276 277 Describe("UserGuid", func() { 278 It("gets the current user's GUID", func() { 279 confirmTestPluginOutput("UserGuid", "[\\w\\d]+-[\\w\\d]+-[\\w\\d]+-[\\w\\d]+-[\\w\\d]+") 280 }) 281 }) 282 283 Describe("Username", func() { 284 It("gets the current username", func() { 285 username, _ := helpers.GetCredentials() 286 confirmTestPluginOutput("Username", username) 287 }) 288 }) 289 })