github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/cloudcontrollerv2_suite_test.go (about) 1 package ccv2_test 2 3 import ( 4 "bytes" 5 "fmt" 6 "log" 7 "net/http" 8 "strings" 9 10 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 11 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/ghttp" 15 16 "testing" 17 ) 18 19 func TestCloudcontrollerv2(t *testing.T) { 20 RegisterFailHandler(Fail) 21 RunSpecs(t, "Cloud Controller V2 Suite") 22 } 23 24 var server *Server 25 26 var _ = SynchronizedBeforeSuite(func() []byte { 27 return []byte{} 28 }, func(data []byte) { 29 server = NewTLSServer() 30 31 // Suppresses ginkgo server logs 32 server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0) 33 }) 34 35 var _ = SynchronizedAfterSuite(func() { 36 server.Close() 37 }, func() {}) 38 39 var _ = BeforeEach(func() { 40 server.Reset() 41 }) 42 43 func NewTestClient(passed ...Config) *Client { 44 return NewClientWithCustomAPIVersion("2.23.0", passed...) 45 } 46 47 func NewClientWithCustomAPIVersion(apiVersion string, passed ...Config) *Client { 48 SetupV2InfoResponse(apiVersion) 49 50 var config Config 51 if len(passed) > 0 { 52 config = passed[0] 53 } else { 54 config = Config{} 55 } 56 config.AppName = "CF CLI API V2 Test" 57 config.AppVersion = "Unknown" 58 59 client := NewClient(config) 60 warnings, err := client.TargetCF(TargetSettings{ 61 SkipSSLValidation: true, 62 URL: server.URL(), 63 }) 64 Expect(err).ToNot(HaveOccurred()) 65 Expect(warnings).To(BeEmpty()) 66 return client 67 } 68 69 func SetupV2InfoResponse(apiVersion string) { 70 serverAPIURL := server.URL()[8:] 71 response := fmt.Sprintf(`{ 72 "name":"", 73 "build":"", 74 "support":"http://support.cloudfoundry.com", 75 "version":0, 76 "description":"", 77 "authorization_endpoint":"https://login.APISERVER", 78 "token_endpoint":"https://uaa.APISERVER", 79 "min_cli_version":null, 80 "min_recommended_cli_version":null, 81 "api_version":"%s", 82 "app_ssh_endpoint":"ssh.APISERVER", 83 "app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a", 84 "routing_endpoint": "https://APISERVER/routing", 85 "app_ssh_oauth_client":"ssh-proxy", 86 "logging_endpoint":"wss://loggregator.APISERVER", 87 "doppler_logging_endpoint":"wss://doppler.APISERVER" 88 }`, apiVersion) 89 response = strings.Replace(response, "APISERVER", serverAPIURL, -1) 90 server.AppendHandlers( 91 CombineHandlers( 92 VerifyRequest(http.MethodGet, "/v2/info"), 93 RespondWith(http.StatusOK, response), 94 ), 95 ) 96 }