github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/plugin/api_test.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("plugin API", func() { 15 BeforeEach(func() { 16 installTestPlugin() 17 }) 18 19 AfterEach(func() { 20 uninstallTestPlugin() 21 }) 22 23 Describe("AccessToken", func() { 24 It("returns the access token", func() { 25 confirmTestPluginOutput("AccessToken", `bearer [\w\d\.]+`) 26 }) 27 }) 28 29 Describe("ApiEndpoint", func() { 30 It("returns the API endpoint", func() { 31 confirmTestPluginOutput("ApiEndpoint", apiURL) 32 }) 33 }) 34 35 Describe("ApiVersion", func() { 36 It("returns the API version", func() { 37 confirmTestPluginOutput("ApiVersion", `2\.\d+\.\d+`) 38 }) 39 }) 40 41 Describe("CliCommand", func() { 42 It("calls the core cli command and outputs to terminal", func() { 43 confirmTestPluginOutput("CliCommand", "API endpoint", "API endpoint") 44 }) 45 }) 46 47 Describe("CliCommandWithoutTerminalOutput", func() { 48 It("calls the core cli command and without outputting to the terminal", func() { 49 session := helpers.CF("CliCommandWithoutTerminalOutput", "target") 50 Eventually(session).Should(Say("API endpoint")) 51 Consistently(session).ShouldNot(Say("API endpoint")) 52 Eventually(session).Should(Exit(0)) 53 }) 54 }) 55 56 Describe("DopplerEndpoint", func() { 57 It("gets Doppler Endpoint", func() { 58 confirmTestPluginOutput("DopplerEndpoint", "wss://doppler") 59 }) 60 }) 61 62 Describe("GetApp", func() { 63 var appName string 64 BeforeEach(func() { 65 createTargetedOrgAndSpace() 66 appName = helpers.PrefixedRandomName("APP") 67 helpers.WithHelloWorldApp(func(appDir string) { 68 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 69 }) 70 }) 71 72 It("gets application information", func() { 73 confirmTestPluginOutputWithArg("GetApp", appName, appName) 74 }) 75 }) 76 77 Describe("GetApps", func() { 78 var appName1, appName2 string 79 BeforeEach(func() { 80 createTargetedOrgAndSpace() 81 appName1 = helpers.PrefixedRandomName("APP") 82 helpers.WithHelloWorldApp(func(appDir string) { 83 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 84 }) 85 appName2 = helpers.PrefixedRandomName("APP") 86 helpers.WithHelloWorldApp(func(appDir string) { 87 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 88 }) 89 }) 90 91 It("gets information for multiple applications", func() { 92 appNameRegexp := fmt.Sprintf("(?:%s|%s)", appName1, appName2) 93 confirmTestPluginOutput("GetApps", appNameRegexp, appNameRegexp) 94 }) 95 }) 96 97 Describe("GetCurrentOrg", func() { 98 It("gets the current targeted org", func() { 99 org, _ := createTargetedOrgAndSpace() 100 confirmTestPluginOutput("GetCurrentOrg", org) 101 }) 102 }) 103 104 Describe("GetCurrentSpace", func() { 105 It("gets the current targeted Space", func() { 106 _, space := createTargetedOrgAndSpace() 107 confirmTestPluginOutput("GetCurrentSpace", space) 108 }) 109 }) 110 111 Describe("GetOrg", func() { 112 It("gets the given org", func() { 113 org, _ := createTargetedOrgAndSpace() 114 confirmTestPluginOutputWithArg("GetOrg", org, org) 115 }) 116 }) 117 118 Describe("GetOrgs", func() { 119 It("gets information for multiple orgs", func() { 120 org1, _ := createTargetedOrgAndSpace() 121 org2, _ := createTargetedOrgAndSpace() 122 orgNameRegexp := fmt.Sprintf("(?:%s|%s)", org1, org2) 123 confirmTestPluginOutput("GetOrgs", orgNameRegexp, orgNameRegexp) 124 }) 125 }) 126 127 Describe("GetOrgUsers", func() { 128 It("returns the org users", func() { 129 org, _ := createTargetedOrgAndSpace() 130 username, _ := helpers.GetCredentials() 131 confirmTestPluginOutputWithArg("GetOrgUsers", org, username) 132 }) 133 }) 134 135 Describe("GetOrgUsers", func() { 136 It("returns the org users", func() { 137 org, _ := createTargetedOrgAndSpace() 138 username, _ := helpers.GetCredentials() 139 confirmTestPluginOutputWithArg("GetOrgUsers", org, username) 140 }) 141 }) 142 143 Describe("GetService and GetServices", func() { 144 var ( 145 serviceInstance1 string 146 serviceInstance2 string 147 broker *fakeservicebroker.FakeServiceBroker 148 ) 149 BeforeEach(func() { 150 createTargetedOrgAndSpace() 151 serviceInstance1 = helpers.PrefixedRandomName("SI1") 152 serviceInstance2 = helpers.PrefixedRandomName("SI2") 153 154 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 155 156 Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0)) 157 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), serviceInstance1)).Should(Exit(0)) 158 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), serviceInstance2)).Should(Exit(0)) 159 }) 160 161 AfterEach(func() { 162 broker.Destroy() 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 })