github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/plugin/api_test.go (about) 1 package plugin 2 3 import ( 4 "regexp" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 "code.cloudfoundry.org/cli/util/configv3" 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("GetApp", func() { 36 var appName string 37 BeforeEach(func() { 38 createTargetedOrgAndSpace() 39 appName = helpers.PrefixedRandomName("APP") 40 helpers.WithHelloWorldApp(func(appDir string) { 41 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 42 }) 43 }) 44 45 It("gets application information", func() { 46 confirmTestPluginOutputWithArg("GetApp", appName, appName) 47 }) 48 }) 49 50 Describe("GetApps", func() { 51 var appName [2]string 52 BeforeEach(func() { 53 createTargetedOrgAndSpace() 54 // Verify apps come back in order of creation, not alphabetically 55 appName[0] = "Z" + helpers.PrefixedRandomName("APP") 56 appName[1] = "A" + helpers.PrefixedRandomName("APP") 57 helpers.WithHelloWorldApp(func(appDir string) { 58 Eventually(helpers.CF("push", appName[0], "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 59 }) 60 helpers.WithHelloWorldApp(func(appDir string) { 61 Eventually(helpers.CF("push", appName[1], "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 62 }) 63 }) 64 65 It("gets application information", func() { 66 confirmTestPluginOutputWithArg("GetApps", appName[0], appName[1]) 67 }) 68 }) 69 70 Describe("GetOrg", func() { 71 var orgName string 72 var orgGUID string 73 var domainName string 74 var domain helpers.Domain 75 76 BeforeEach(func() { 77 orgName = helpers.NewOrgName() 78 helpers.CreateOrg(orgName) 79 helpers.TargetOrg(orgName) 80 orgGUID = helpers.GetOrgGUID(orgName) 81 82 domainName = helpers.DomainName("get-org-test") 83 domain = helpers.NewDomain(orgName, domainName) 84 domain.Create() 85 }) 86 87 AfterEach(func() { 88 domain.Delete() 89 }) 90 91 It("gets the organization information", func() { 92 confirmTestPluginOutputWithArg("GetOrg", orgName, orgName, orgGUID, domainName) 93 }) 94 95 When("the org has metadata", func() { 96 BeforeEach(func() { 97 Eventually(helpers.CF("set-label", "org", orgName, "orgType=production")).Should(Exit(0)) 98 }) 99 It("Displays the metadata correctly", func() { 100 confirmTestPluginOutputWithArg("GetOrg", orgName, regexp.QuoteMeta("Labels:map[orgType:{Value:production")) 101 }) 102 }) 103 104 When("the org does not exist", func() { 105 It("Displays a useful error message", func() { 106 confirmTestPluginOutputWithArg("GetOrg", "blahblahblah", "Error GetOrg: Organization 'blahblahblah' not found") 107 }) 108 }) 109 }) 110 111 Describe("GetSpace", func() { 112 var orgName string 113 var spaceName string 114 var spaceGUID string 115 116 BeforeEach(func() { 117 orgName = helpers.NewOrgName() 118 spaceName = helpers.NewSpaceName() 119 helpers.CreateOrgAndSpace(orgName, spaceName) 120 helpers.TargetOrg(orgName) 121 spaceGUID = helpers.GetSpaceGUID(spaceName) 122 }) 123 AfterEach(func() { 124 helpers.QuickDeleteOrg(orgName) 125 }) 126 127 It("gets the space information", func() { 128 confirmTestPluginOutputWithArg("GetSpace", spaceName, spaceGUID) 129 }) 130 131 When("the space has metadata", func() { 132 BeforeEach(func() { 133 Eventually(helpers.CF("set-label", "space", spaceName, "spaceType=production")).Should(Exit(0)) 134 }) 135 It("Displays the metadata correctly", func() { 136 confirmTestPluginOutputWithArg("GetSpace", spaceName, "spaceType", "production") 137 }) 138 }) 139 140 When("the space does not exist", func() { 141 It("Displays a useful error message", func() { 142 confirmTestPluginOutputWithArg("GetSpace", "blahblahblah", "Error GetSpace: Space 'blahblahblah' not found") 143 }) 144 }) 145 }) 146 147 Describe("GetSpaces", func() { 148 var orgName string 149 150 BeforeEach(func() { 151 orgName = helpers.CreateAndTargetOrg() 152 }) 153 154 AfterEach(func() { 155 helpers.QuickDeleteOrg(orgName) 156 }) 157 158 Context("when there are no spaces", func() { 159 It("gets no spaces", func() { 160 confirmTestPluginOutputWithArg("GetSpaces", "No spaces found") 161 }) 162 }) 163 164 Context("when there are spaces", func() { 165 var spaceName string 166 var spaceGUID string 167 var spaceName2 string 168 var spaceGUID2 string 169 170 BeforeEach(func() { 171 spaceName = helpers.NewSpaceName() 172 helpers.CreateSpace(spaceName) 173 spaceName2 = helpers.NewSpaceName() 174 helpers.CreateSpace(spaceName2) 175 spaceGUID = helpers.GetSpaceGUID(spaceName) 176 spaceGUID2 = helpers.GetSpaceGUID(spaceName2) 177 }) 178 179 It("gets the spaces' information", func() { 180 // Results are in random order so make two separate calls 181 confirmTestPluginOutputWithArg("GetSpaces", spaceName, spaceGUID) 182 confirmTestPluginOutputWithArg("GetSpaces", spaceName2, spaceGUID2) 183 }) 184 185 When("the spaces have metadata", func() { 186 BeforeEach(func() { 187 Eventually(helpers.CF("set-label", "space", spaceName, "spaceType=production")).Should(Exit(0)) 188 Eventually(helpers.CF("set-label", "space", spaceName2, "squadron=goose")).Should(Exit(0)) 189 }) 190 It("Displays the metadata", func() { 191 // Results are in random order so make two separate calls 192 confirmTestPluginOutputWithArg("GetSpaces", spaceName, "spaceType", "production") 193 confirmTestPluginOutputWithArg("GetSpaces", spaceName2, "squadron", "goose") 194 }) 195 }) 196 }) 197 }) 198 199 Describe("GetCurrentSpace", func() { 200 It("gets the current targeted Space", func() { 201 _, space := createTargetedOrgAndSpace() 202 confirmTestPluginOutput("GetCurrentSpace", space) 203 }) 204 }) 205 206 Describe("GetCurrentOrg", func() { 207 It("gets the current targeted Org", func() { 208 org, _ := createTargetedOrgAndSpace() 209 confirmTestPluginOutput("GetCurrentOrg", org) 210 }) 211 }) 212 213 Describe("IsLoggedIn", func() { 214 When("logged in", func() { 215 It("returns true", func() { 216 confirmTestPluginOutput("IsLoggedIn", "true") 217 }) 218 }) 219 When("logged out", func() { 220 BeforeEach(func() { 221 helpers.LogoutCF() 222 }) 223 It("returns false", func() { 224 confirmTestPluginOutput("IsLoggedIn", "false") 225 }) 226 }) 227 }) 228 229 Describe("Username", func() { 230 It("gets the current user's name", func() { 231 username := getUsername() 232 confirmTestPluginOutput("Username", username) 233 }) 234 235 When("not logged in", func() { 236 BeforeEach(func() { 237 helpers.LogoutCF() 238 }) 239 It("returns an error", func() { 240 confirmTestPluginOutput("Username", "not logged in") 241 }) 242 }) 243 244 When("the token is invalid", func() { 245 var accessToken string 246 247 BeforeEach(func() { 248 helpers.SetConfig(func(config *configv3.Config) { 249 accessToken = config.ConfigFile.AccessToken 250 config.ConfigFile.AccessToken = accessToken + "***" 251 }) 252 }) 253 AfterEach(func() { 254 helpers.SetConfig(func(config *configv3.Config) { 255 config.ConfigFile.AccessToken = accessToken 256 }) 257 }) 258 259 When("running a v7 plugin command", func() { 260 It("complains about the token", func() { 261 session := helpers.CF("Username") 262 Eventually(session).Should(Say("illegal base64 data at input byte 342")) 263 }) 264 }) 265 }) 266 }) 267 268 Describe("IsSkipSSLValidation", func() { 269 When("--skip-ssl-validation is not specified", func() { 270 BeforeEach(func() { 271 if helpers.SkipSSLValidation() { 272 Skip("Test is being run with skip ssl validation") 273 } 274 }) 275 It("returns false", func() { 276 confirmTestPluginOutput("IsSkipSSLValidation", "false") 277 }) 278 }) 279 When("--skip-ssl-validation is specified", func() { 280 BeforeEach(func() { 281 Eventually(helpers.CF("api", apiURL, "--skip-ssl-validation")).Should(Exit(0)) 282 }) 283 It("returns true", func() { 284 confirmTestPluginOutput("IsSkipSSLValidation", "true") 285 }) 286 }) 287 }) 288 289 })