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