github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/ccv3fakes" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/ghttp" 14 15 "testing" 16 ) 17 18 func TestCcv3(t *testing.T) { 19 RegisterFailHandler(Fail) 20 RunSpecs(t, "Cloud Controller V3 Suite") 21 } 22 23 var server *Server 24 25 var _ = BeforeEach(func() { 26 server = NewTLSServer() 27 28 // Suppresses ginkgo server logs 29 server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0) 30 }) 31 32 var _ = AfterEach(func() { 33 server.Close() 34 }) 35 36 func NewTestClient(config ...Config) (*Client, *ccv3fakes.FakeClock) { 37 SetupV3Response() 38 var client *Client 39 fakeClock := new(ccv3fakes.FakeClock) 40 41 if config != nil { 42 client = TestClient(config[0], fakeClock) 43 } else { 44 client = TestClient(Config{AppName: "CF CLI API V3 Test", AppVersion: "Unknown"}, fakeClock) 45 } 46 warnings, err := client.TargetCF(TargetSettings{ 47 SkipSSLValidation: true, 48 URL: server.URL(), 49 }) 50 Expect(err).ToNot(HaveOccurred()) 51 Expect(warnings).To(BeEmpty()) 52 53 return client, fakeClock 54 } 55 56 func SetupV3Response() { 57 serverURL := server.URL() 58 rootResponse := strings.Replace(`{ 59 "links": { 60 "self": { 61 "href": "SERVER_URL" 62 }, 63 "cloud_controller_v2": { 64 "href": "SERVER_URL/v2", 65 "meta": { 66 "version": "2.64.0" 67 } 68 }, 69 "cloud_controller_v3": { 70 "href": "SERVER_URL/v3", 71 "meta": { 72 "version": "3.0.0-alpha.5" 73 } 74 }, 75 "uaa": { 76 "href": "https://uaa.bosh-lite.com" 77 } 78 } 79 }`, "SERVER_URL", serverURL, -1) 80 81 server.AppendHandlers( 82 CombineHandlers( 83 VerifyRequest(http.MethodGet, "/"), 84 RespondWith(http.StatusOK, rootResponse), 85 ), 86 ) 87 88 v3Response := strings.Replace(`{ 89 "links": { 90 "self": { 91 "href": "SERVER_URL/v3" 92 }, 93 "apps": { 94 "href": "SERVER_URL/v3/apps" 95 }, 96 "tasks": { 97 "href": "SERVER_URL/v3/tasks" 98 }, 99 "isolation_segments": { 100 "href": "SERVER_URL/v3/isolation_segments" 101 }, 102 "builds": { 103 "href": "SERVER_URL/v3/builds" 104 }, 105 "organizations": { 106 "href": "SERVER_URL/v3/organizations" 107 }, 108 "organization_quotas": { 109 "href": "SERVER_URL/v3/organization_quotas" 110 }, 111 "service_brokers": { 112 "href": "SERVER_URL/v3/service_brokers" 113 }, 114 "service_instances": { 115 "href": "SERVER_URL/v3/service_instances" 116 }, 117 "spaces": { 118 "href": "SERVER_URL/v3/spaces" 119 }, 120 "packages": { 121 "href": "SERVER_URL/v3/packages" 122 }, 123 "processes": { 124 "href": "SERVER_URL/v3/processes" 125 }, 126 "droplets": { 127 "href": "SERVER_URL/v3/droplets" 128 }, 129 "audit_events": { 130 "href": "SERVER_URL/v3/audit_events" 131 }, 132 "domains": { 133 "href": "SERVER_URL/v3/domains" 134 }, 135 "deployments": { 136 "href": "SERVER_URL/v3/deployments" 137 }, 138 "stacks": { 139 "href": "SERVER_URL/v3/stacks" 140 }, 141 "buildpacks": { 142 "href": "SERVER_URL/v3/buildpacks" 143 }, 144 "feature_flags": { 145 "href": "SERVER_URL/v3/feature_flags" 146 }, 147 "resource_matches": { 148 "href": "SERVER_URL/v3/resource_matches" 149 }, 150 "roles": { 151 "href": "SERVER_URL/v3/roles" 152 }, 153 "routes": { 154 "href": "SERVER_URL/v3/routes" 155 }, 156 "users": { 157 "href": "SERVER_URL/v3/users" 158 }, 159 "environment_variable_groups": { 160 "href": "SERVER_URL/v3/environment_variable_groups" 161 } 162 } 163 }`, "SERVER_URL", serverURL, -1) 164 165 server.AppendHandlers( 166 CombineHandlers( 167 VerifyRequest(http.MethodGet, "/v3"), 168 RespondWith(http.StatusOK, v3Response), 169 ), 170 ) 171 }