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