github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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("GetCurrentSpace", func() { 112 It("gets the current targeted Space", func() { 113 _, space := createTargetedOrgAndSpace() 114 confirmTestPluginOutput("GetCurrentSpace", space) 115 }) 116 }) 117 118 Describe("GetCurrentOrg", func() { 119 It("gets the current targeted Org", func() { 120 org, _ := createTargetedOrgAndSpace() 121 confirmTestPluginOutput("GetCurrentOrg", org) 122 }) 123 }) 124 125 Describe("IsLoggedIn", func() { 126 When("logged in", func() { 127 It("returns true", func() { 128 confirmTestPluginOutput("IsLoggedIn", "true") 129 }) 130 }) 131 When("logged out", func() { 132 BeforeEach(func() { 133 helpers.LogoutCF() 134 }) 135 It("returns false", func() { 136 confirmTestPluginOutput("IsLoggedIn", "false") 137 }) 138 }) 139 }) 140 141 Describe("Username", func() { 142 It("gets the current user's name", func() { 143 username := getUsername() 144 confirmTestPluginOutput("Username", username) 145 }) 146 147 When("not logged in", func() { 148 BeforeEach(func() { 149 helpers.LogoutCF() 150 }) 151 It("returns an error", func() { 152 confirmTestPluginOutput("Username", "not logged in") 153 }) 154 }) 155 156 When("the token is invalid", func() { 157 var accessToken string 158 159 BeforeEach(func() { 160 helpers.SetConfig(func(config *configv3.Config) { 161 accessToken = config.ConfigFile.AccessToken 162 config.ConfigFile.AccessToken = accessToken + "***" 163 }) 164 }) 165 AfterEach(func() { 166 helpers.SetConfig(func(config *configv3.Config) { 167 config.ConfigFile.AccessToken = accessToken 168 }) 169 }) 170 171 When("running a v7 plugin command", func() { 172 It("complains about the token", func() { 173 session := helpers.CF("Username") 174 Eventually(session).Should(Say("illegal base64 data at input byte 342")) 175 }) 176 }) 177 }) 178 }) 179 180 Describe("IsSkipSSLValidation", func() { 181 When("--skip-ssl-validation is not specified", func() { 182 BeforeEach(func() { 183 if helpers.SkipSSLValidation() { 184 Skip("Test is being run with skip ssl validation") 185 } 186 }) 187 It("returns false", func() { 188 confirmTestPluginOutput("IsSkipSSLValidation", "false") 189 }) 190 }) 191 When("--skip-ssl-validation is specified", func() { 192 BeforeEach(func() { 193 Eventually(helpers.CF("api", apiURL, "--skip-ssl-validation")).Should(Exit(0)) 194 }) 195 It("returns true", func() { 196 confirmTestPluginOutput("IsSkipSSLValidation", "true") 197 }) 198 }) 199 }) 200 201 })