github.com/sleungcy-sap/cli@v7.1.0+incompatible/api/cloudcontroller/ccv2/info_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 "strings" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 8 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("Info", func() { 16 var ( 17 serverAPIURL string 18 19 client *Client 20 ) 21 22 BeforeEach(func() { 23 serverAPIURL = server.URL()[8:] 24 client = NewTestClient() 25 }) 26 27 Describe("Info", func() { 28 BeforeEach(func() { 29 response := `{ 30 "name":"faceman test server", 31 "build":"", 32 "support":"http://support.cloudfoundry.com", 33 "version":0, 34 "description":"", 35 "authorization_endpoint":"https://login.APISERVER", 36 "min_cli_version":"6.22.1", 37 "min_recommended_cli_version":null, 38 "api_version":"2.59.0", 39 "app_ssh_endpoint":"ssh.APISERVER", 40 "app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a", 41 "routing_endpoint": "https://APISERVER/routing", 42 "app_ssh_oauth_client":"ssh-proxy", 43 "logging_endpoint":"wss://loggregator.APISERVER", 44 "doppler_logging_endpoint":"wss://doppler.APISERVER" 45 }` 46 response = strings.Replace(response, "APISERVER", serverAPIURL, -1) 47 server.AppendHandlers( 48 CombineHandlers( 49 VerifyRequest(http.MethodGet, "/v2/info"), 50 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 51 ), 52 ) 53 }) 54 55 It("returns back the CC Information", func() { 56 info, _, err := client.Info() 57 Expect(err).NotTo(HaveOccurred()) 58 59 Expect(info.APIVersion).To(Equal("2.59.0")) 60 Expect(info.AuthorizationEndpoint).To(MatchRegexp("https://login.%s", serverAPIURL)) 61 Expect(info.DopplerEndpoint).To(MatchRegexp("wss://doppler.%s", serverAPIURL)) 62 Expect(info.MinCLIVersion).To(Equal("6.22.1")) 63 Expect(info.MinimumRecommendedCLIVersion).To(BeEmpty()) 64 Expect(info.Name).To(Equal("faceman test server")) 65 Expect(info.RoutingEndpoint).To(MatchRegexp("https://%s/routing", serverAPIURL)) 66 }) 67 68 It("sets the http endpoint and warns user", func() { 69 _, warnings, err := client.Info() 70 Expect(err).NotTo(HaveOccurred()) 71 Expect(warnings).To(ContainElement("this is a warning")) 72 }) 73 }) 74 75 When("the API response gives a bad API endpoint", func() { 76 BeforeEach(func() { 77 response := `i am banana` 78 server.AppendHandlers( 79 CombineHandlers( 80 VerifyRequest(http.MethodGet, "/v2/info"), 81 RespondWith(http.StatusNotFound, response), 82 ), 83 ) 84 }) 85 86 It("returns back an APINotFoundError", func() { 87 _, _, err := client.Info() 88 Expect(err).To(MatchError(ccerror.APINotFoundError{URL: server.URL() + "/"})) 89 }) 90 }) 91 })