github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/api/cloudcontroller/ccv2/info_test.go (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  	"strings"
     6  
     7  	"github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccerror"
     8  	. "github.com/liamawhite/cli-with-i18n/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  					"token_endpoint":"https://uaa.APISERVER",
    37  					"min_cli_version":"6.22.1",
    38  					"min_recommended_cli_version":null,
    39  					"api_version":"2.59.0",
    40  					"app_ssh_endpoint":"ssh.APISERVER",
    41  					"app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a",
    42  					"routing_endpoint": "https://APISERVER/routing",
    43  					"app_ssh_oauth_client":"ssh-proxy",
    44  					"logging_endpoint":"wss://loggregator.APISERVER",
    45  					"doppler_logging_endpoint":"wss://doppler.APISERVER"
    46  				}`
    47  			response = strings.Replace(response, "APISERVER", serverAPIURL, -1)
    48  			server.AppendHandlers(
    49  				CombineHandlers(
    50  					VerifyRequest(http.MethodGet, "/v2/info"),
    51  					RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    52  				),
    53  			)
    54  		})
    55  
    56  		It("returns back the CC Information", func() {
    57  			info, _, err := client.Info()
    58  			Expect(err).NotTo(HaveOccurred())
    59  
    60  			Expect(info.APIVersion).To(Equal("2.59.0"))
    61  			Expect(info.AuthorizationEndpoint).To(MatchRegexp("https://login.%s", serverAPIURL))
    62  			Expect(info.DopplerEndpoint).To(MatchRegexp("wss://doppler.%s", serverAPIURL))
    63  			Expect(info.MinCLIVersion).To(Equal("6.22.1"))
    64  			Expect(info.MinimumRecommendedCLIVersion).To(BeEmpty())
    65  			Expect(info.Name).To(Equal("faceman test server"))
    66  			Expect(info.RoutingEndpoint).To(MatchRegexp("https://%s/routing", serverAPIURL))
    67  			Expect(info.TokenEndpoint).To(MatchRegexp("https://uaa.%s", serverAPIURL))
    68  		})
    69  
    70  		It("sets the http endpoint and warns user", func() {
    71  			_, warnings, err := client.Info()
    72  			Expect(err).NotTo(HaveOccurred())
    73  			Expect(warnings).To(ContainElement("this is a warning"))
    74  		})
    75  	})
    76  
    77  	Context("when the API response gives a bad API endpoint", func() {
    78  		BeforeEach(func() {
    79  			response := `i am banana`
    80  			server.AppendHandlers(
    81  				CombineHandlers(
    82  					VerifyRequest(http.MethodGet, "/v2/info"),
    83  					RespondWith(http.StatusNotFound, response),
    84  				),
    85  			)
    86  		})
    87  
    88  		It("returns back an APINotFoundError", func() {
    89  			_, _, err := client.Info()
    90  			Expect(err).To(MatchError(ccerror.APINotFoundError{URL: server.URL()}))
    91  		})
    92  	})
    93  })