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