github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv3/ccv3_suite_test.go (about) 1 package ccv3_test 2 3 import ( 4 "bytes" 5 "log" 6 "net/http" 7 "strings" 8 9 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/ghttp" 13 14 "testing" 15 ) 16 17 func TestCcv3(t *testing.T) { 18 RegisterFailHandler(Fail) 19 RunSpecs(t, "Cloud Controller V3 Suite") 20 } 21 22 var server *Server 23 24 var _ = SynchronizedBeforeSuite(func() []byte { 25 return []byte{} 26 }, func(data []byte) { 27 server = NewTLSServer() 28 29 // Suppresses ginkgo server logs 30 server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0) 31 }) 32 33 var _ = SynchronizedAfterSuite(func() { 34 server.Close() 35 }, func() {}) 36 37 var _ = BeforeEach(func() { 38 server.Reset() 39 }) 40 41 func NewTestClient(config ...Config) *Client { 42 SetupV3Response() 43 var client *Client 44 45 if config != nil { 46 client = NewClient(config[0]) 47 } else { 48 client = NewClient(Config{AppName: "CF CLI API V3 Test", AppVersion: "Unknown"}) 49 } 50 warnings, err := client.TargetCF(TargetSettings{ 51 SkipSSLValidation: true, 52 URL: server.URL(), 53 }) 54 Expect(err).ToNot(HaveOccurred()) 55 Expect(warnings).To(BeEmpty()) 56 57 return client 58 } 59 60 func SetupV3Response() { 61 serverURL := server.URL() 62 rootResponse := strings.Replace(`{ 63 "links": { 64 "self": { 65 "href": "SERVER_URL" 66 }, 67 "cloud_controller_v2": { 68 "href": "SERVER_URL/v2", 69 "meta": { 70 "version": "2.64.0" 71 } 72 }, 73 "cloud_controller_v3": { 74 "href": "SERVER_URL/v3", 75 "meta": { 76 "version": "3.0.0-alpha.5" 77 } 78 }, 79 "uaa": { 80 "href": "https://uaa.bosh-lite.com" 81 } 82 } 83 }`, "SERVER_URL", serverURL, -1) 84 85 server.AppendHandlers( 86 CombineHandlers( 87 VerifyRequest(http.MethodGet, "/"), 88 RespondWith(http.StatusOK, rootResponse), 89 ), 90 ) 91 92 v3Response := strings.Replace(`{ 93 "links": { 94 "self": { 95 "href": "SERVER_URL/v3" 96 }, 97 "apps": { 98 "href": "SERVER_URL/v3/apps" 99 }, 100 "tasks": { 101 "href": "SERVER_URL/v3/tasks" 102 }, 103 "isolation_segments": { 104 "href": "SERVER_URL/v3/isolation_segments" 105 }, 106 "builds": { 107 "href": "SERVER_URL/v3/builds" 108 }, 109 "organizations": { 110 "href": "SERVER_URL/v3/organizations" 111 }, 112 "service_instances": { 113 "href": "SERVER_URL/v3/service_instances" 114 }, 115 "spaces": { 116 "href": "SERVER_URL/v3/spaces" 117 }, 118 "packages": { 119 "href": "SERVER_URL/v3/packages" 120 }, 121 "processes": { 122 "href": "SERVER_URL/v3/processes" 123 }, 124 "droplets": { 125 "href": "SERVER_URL/v3/droplets" 126 } 127 } 128 }`, "SERVER_URL", serverURL, -1) 129 130 server.AppendHandlers( 131 CombineHandlers( 132 VerifyRequest(http.MethodGet, "/v3"), 133 RespondWith(http.StatusOK, v3Response), 134 ), 135 ) 136 }