func createUsersByRoleEndpoints(rolePath string) (ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) { nextUrl := rolePath + "?page=2" ccReqs = []testnet.TestRequest{ testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: rolePath, Response: testnet.TestResponse{ Status: http.StatusOK, Body: fmt.Sprintf(` { "next_url": "%s", "resources": [ {"metadata": {"guid": "user-1-guid"}, "entity": {}} ] }`, nextUrl)}}), testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: nextUrl, Response: testnet.TestResponse{ Status: http.StatusOK, Body: ` { "resources": [ {"metadata": {"guid": "user-2-guid"}, "entity": {}}, {"metadata": {"guid": "user-3-guid"}, "entity": {}} ] }`}}), } uaaReqs = []testnet.TestRequest{ testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: fmt.Sprintf( "/Users?attributes=id,userName&filter=%s", url.QueryEscape(`Id eq "user-1-guid" or Id eq "user-2-guid" or Id eq "user-3-guid"`)), Response: testnet.TestResponse{ Status: http.StatusOK, Body: ` { "resources": [ { "id": "user-1-guid", "userName": "******" }, { "id": "user-2-guid", "userName": "******" }, { "id": "user-3-guid", "userName": "******" } ] }`}})} return }
func deleteSharedDomainReq(statusCode int) testnet.TestRequest { return testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "DELETE", Path: "/v2/shared_domains/my-domain-guid?recursive=true", Response: testnet.TestResponse{Status: statusCode}, }) }
func uploadApplicationRequest(zipCheck func(*zip.Reader)) testnet.TestRequest { return testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/apps/my-cool-app-guid/bits", Matcher: uploadBodyMatcher(zipCheck), Response: testnet.TestResponse{ Status: http.StatusCreated, Body: ` { "metadata":{ "guid": "my-job-guid", "url": "/v2/jobs/my-job-guid" } } `}, }) }
func testSpacesDidNotFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) { request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", orgGuid), Response: testnet.TestResponse{ Status: http.StatusOK, Body: ` { "resources": [ ] }`, }, }) ts, handler, repo := createSpacesRepo(request) defer ts.Close() _, apiErr := findByName(repo, "Space1") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr.(*errors.ModelNotFoundError)).NotTo(BeNil()) }
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("AppSummaryRepository", func() { var ( testServer *httptest.Server handler *testnet.TestHandler repo AppSummaryRepository ) BeforeEach(func() { getAppSummariesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/spaces/my-space-guid/summary", Response: testnet.TestResponse{ Status: http.StatusOK, Body: getAppSummariesResponseBody, }, }) testServer, handler = testnet.NewServer([]testnet.TestRequest{getAppSummariesRequest}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(testServer.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerAppSummaryRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() })
} }) AfterEach(func() { testServer.Close() }) It("uploads zip files", func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/apps/my-cool-app-guid/bits", Matcher: uploadBodyMatcher(defaultZipCheck), Response: testnet.TestResponse{ Status: http.StatusCreated, Body: ` { "metadata":{ "guid": "my-job-guid", "url": "/v2/jobs/my-job-guid" } }`, }, }), createProgressEndpoint("running"), createProgressEndpoint("finished"), ) apiErr := repo.UploadBits("my-cool-app-guid", uploadFile, []resources.AppFileResource{file1, file2}) Expect(apiErr).NotTo(HaveOccurred()) })
func testSpacesFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) { findSpaceByNameResponse := testnet.TestResponse{ Status: http.StatusOK, Body: ` { "resources": [ { "metadata": { "guid": "space1-guid" }, "entity": { "name": "Space1", "organization_guid": "org1-guid", "organization": { "metadata": { "guid": "org1-guid" }, "entity": { "name": "Org1" } }, "apps": [ { "metadata": { "guid": "app1-guid" }, "entity": { "name": "app1" } }, { "metadata": { "guid": "app2-guid" }, "entity": { "name": "app2" } } ], "domains": [ { "metadata": { "guid": "domain1-guid" }, "entity": { "name": "domain1" } } ], "service_instances": [ { "metadata": { "guid": "service1-guid" }, "entity": { "name": "service1" } } ] } } ] }`} request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", orgGuid), Response: findSpaceByNameResponse, }) ts, handler, repo := createSpacesRepo(request) defer ts.Close() space, apiErr := findByName(repo, "Space1") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) Expect(space.Name).To(Equal("Space1")) Expect(space.Guid).To(Equal("space1-guid")) Expect(space.Organization.Guid).To(Equal("org1-guid")) Expect(len(space.Applications)).To(Equal(2)) Expect(space.Applications[0].Guid).To(Equal("app1-guid")) Expect(space.Applications[1].Guid).To(Equal("app2-guid")) Expect(len(space.Domains)).To(Equal(1)) Expect(space.Domains[0].Guid).To(Equal("domain1-guid")) Expect(len(space.ServiceInstances)).To(Equal(1)) Expect(space.ServiceInstances[0].Guid).To(Equal("service1-guid")) Expect(apiErr).NotTo(HaveOccurred()) return }
) var _ = Describe("Service Brokers Repo", func() { It("lists services brokers", func() { firstRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/service_brokers", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{ "next_url": "/v2/service_brokers?page=2", "resources": [ { "metadata": { "guid":"found-guid-1" }, "entity": { "name": "found-name-1", "broker_url": "http://found.example.com-1", "auth_username": "******", "auth_password": "******" } } ] }`, }, }) secondRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/service_brokers?page=2",
Name: "the-space-name", }) gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerRouteRepository(configRepo, gateway) }) AfterEach(func() { ts.Close() }) Describe("List routes", func() { It("lists routes in the current space", func() { ts, handler = testnet.NewServer([]testnet.TestRequest{ testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/spaces/the-space-guid/routes?inline-relations-depth=1", Response: firstPageRoutesResponse, }), testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/spaces/the-space-guid/routes?inline-relations-depth=1&page=2", Response: secondPageRoutesResponse, }), }) configRepo.SetApiEndpoint(ts.URL) routes := []models.Route{} apiErr := repo.ListRoutes(func(route models.Route) bool { routes = append(routes, route) return true })
. "github.com/nttlabs/cli/testhelpers/matchers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Organization Repository", func() { Describe("listing organizations", func() { It("lists the orgs from the the /v2/orgs endpoint", func() { firstPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/organizations", Response: testnet.TestResponse{Status: http.StatusOK, Body: `{ "next_url": "/v2/organizations?page=2", "resources": [ { "metadata": { "guid": "org1-guid" }, "entity": { "name": "Org1" } }, { "metadata": { "guid": "org2-guid" }, "entity": { "name": "Org2" } } ]}`}, }) secondPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/organizations?page=2", Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [ { "metadata": { "guid": "org3-guid" }, "entity": { "name": "Org3" }
config.SetApiEndpoint(ccServer.URL) } setupUAAServer := func(requests ...testnet.TestRequest) { uaaServer, uaaHandler = testnet.NewServer(requests) config.SetUaaEndpoint(uaaServer.URL) } Describe("listing the users with a given role", func() { Context("when there are no users in the given org", func() { It("lists the users in a org with a given role", func() { ccReqs := []testnet.TestRequest{ testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/organizations/my-org-guid/managers", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{"resources": []}`, }}), } setupCCServer(ccReqs...) users, apiErr := repo.ListUsersInOrgForRole("my-org-guid", models.ORG_MANAGER) Expect(ccHandler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) Expect(len(users)).To(Equal(0)) }) })
"github.com/nttlabs/cli/cf/net" testconfig "github.com/nttlabs/cli/testhelpers/configuration" testnet "github.com/nttlabs/cli/testhelpers/net" testterm "github.com/nttlabs/cli/testhelpers/terminal" . "github.com/nttlabs/cli/cf/api/password" . "github.com/nttlabs/cli/testhelpers/matchers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("CloudControllerPasswordRepository", func() { It("updates your password", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/Users/my-user-guid/password", Matcher: testnet.RequestBodyMatcher(`{"password":"******","oldPassword":"******"}`), Response: testnet.TestResponse{Status: http.StatusOK}, }) passwordUpdateServer, handler, repo := createPasswordRepo(req) defer passwordUpdateServer.Close() apiErr := repo.UpdatePassword("old-password", "new-password") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) }) }) func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo PasswordRepository) { passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req})
writer.WriteHeader(http.StatusInternalServerError) return } writer.WriteHeader(http.StatusOK) fmt.Fprint(writer, expectedResponse) } listFilesServer := httptest.NewServer(http.HandlerFunc(listFilesEndpoint)) defer listFilesServer.Close() req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/apps/my-app-guid/instances/1/files/some/path", Response: testnet.TestResponse{ Status: http.StatusTemporaryRedirect, Header: http.Header{ "Location": {fmt.Sprintf("%s/some/path", listFilesServer.URL)}, }, }, }) listFilesRedirectServer, handler := testnet.NewServer([]testnet.TestRequest{req}) defer listFilesRedirectServer.Close() configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(listFilesRedirectServer.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo := NewCloudControllerAppFilesRepository(configRepo, gateway) list, err := repo.ListFiles("my-app-guid", 1, "some/path")
It("should always return back the first shared domain", func() { domain, apiErr := repo.FirstOrDefault("my-org-guid", nil) Expect(apiErr).NotTo(HaveOccurred()) Expect(domain.Guid).To(Equal("shared-domain1-guid")) }) }) It("finds a domain by name", func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/domains?inline-relations-depth=1&q=name%3Adomain2.cf-app.com", Response: testnet.TestResponse{Status: http.StatusOK, Body: ` { "resources": [ { "metadata": { "guid": "domain2-guid" }, "entity": { "name": "domain2.cf-app.com" } } ] }`}, })) domain, apiErr := repo.FindByName("domain2.cf-app.com") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) Expect(domain.Name).To(Equal("domain2.cf-app.com")) Expect(domain.Guid).To(Equal("domain2-guid")) })
Expect(servicePlansFields[0].Public).To(BeTrue()) Expect(servicePlansFields[0].Active).To(BeTrue()) Expect(servicePlansFields[1].Name).To(Equal("The small second")) Expect(servicePlansFields[1].Guid).To(Equal("the-small-second")) Expect(servicePlansFields[1].Free).To(BeTrue()) Expect(servicePlansFields[1].Public).To(BeFalse()) Expect(servicePlansFields[1].Active).To(BeFalse()) }) }) }) Describe(".Update", func() { BeforeEach(func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/service_plans/my-service-plan-guid", Matcher: testnet.RequestBodyMatcher(`{"name":"my-service-plan", "free":true, "description":"descriptive text", "public":true, "service_guid":"service-guid"}`), Response: testnet.TestResponse{Status: http.StatusCreated}, })) }) It("Updates the service to public", func() { servicePlan := models.ServicePlanFields{ Name: "my-service-plan", Guid: "my-service-plan-guid", Description: "descriptive text", Free: true, Public: false, } err := repo.Update(servicePlan, "service-guid", true) Expect(testHandler).To(HaveAllRequestsCalled())
Expect(quotas[0].Guid).To(Equal("my-quota-guid")) Expect(quotas[0].Name).To(Equal("my-remote-quota")) Expect(quotas[0].MemoryLimit).To(Equal(int64(1024))) Expect(quotas[0].RoutesLimit).To(Equal(123)) Expect(quotas[0].ServicesLimit).To(Equal(321)) Expect(quotas[1].Guid).To(Equal("my-quota-guid2")) Expect(quotas[2].Guid).To(Equal("my-quota-guid3")) }) }) Describe("AssignQuotaToOrg", func() { It("sets the quota for an organization", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/organizations/my-org-guid", Matcher: testnet.RequestBodyMatcher(`{"quota_definition_guid":"my-quota-guid"}`), Response: testnet.TestResponse{Status: http.StatusCreated}, }) setupTestServer(req) err := repo.AssignQuotaToOrg("my-org-guid", "my-quota-guid") Expect(testHandler).To(HaveAllRequestsCalled()) Expect(err).NotTo(HaveOccurred()) }) }) Describe("Create", func() { It("creates a new quota with the given name", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "POST",
It("sets the environment variables in the running group", func() { err := repo.SetRunning(`{"abc": "one-two-three", "def": 456}`) Expect(err).NotTo(HaveOccurred()) Expect(testHandler).To(HaveAllRequestsCalled()) }) }) }) var listRunningRequest = testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/config/environment_variable_groups/running", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{ "abc": 123, "do-re-mi": "fa-sol-la-ti" }`, }, }) var listStagingRequest = testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/config/environment_variable_groups/staging", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{ "abc": 123, "do-re-mi": "fa-sol-la-ti" }`,
Expect(testHandler).To(HaveAllRequestsCalled()) Expect(err).NotTo(HaveOccurred()) Expect(stack).To(Equal(models.Stack{ Name: "custom-linux", Guid: "custom-linux-guid", })) }) }) Context("when a stack does not exist", func() { BeforeEach(func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/stacks?q=name%3Alinux", Response: testnet.TestResponse{ Status: http.StatusOK, Body: ` { "resources": []}`, }})) }) It("returns an error", func() { _, err := repo.FindByName("linux") Expect(testHandler).To(HaveAllRequestsCalled()) Expect(err).To(BeAssignableToTypeOf(&errors.ModelNotFoundError{})) }) }) }) Describe("FindAll", func() {
configRepo.SetAccessToken("BEARER my_access_token") gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerServiceRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) Describe("GetAllServiceOfferings", func() { BeforeEach(func() { setupTestServer( testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/services?inline-relations-depth=1", Response: firstOfferingsResponse, }), testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/services?inline-relations-depth=1", Response: multipleOfferingsResponse, }), ) }) It("gets all public service offerings", func() { offerings, err := repo.GetAllServiceOfferings() Expect(testHandler).To(HaveAllRequestsCalled()) Expect(err).NotTo(HaveOccurred())
configRepo = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerServiceBindingRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) Describe("Create", func() { Context("when the service binding can be created", func() { BeforeEach(func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "POST", Path: "/v2/service_bindings", Matcher: testnet.RequestBodyMatcher(`{"app_guid":"my-app-guid","service_instance_guid":"my-service-instance-guid","async":true}`), Response: testnet.TestResponse{Status: http.StatusCreated}, })) }) It("creates the service binding", func() { apiErr := repo.Create("my-service-instance-guid", "my-app-guid") Expect(testHandler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) }) }) Context("when an error occurs", func() { BeforeEach(func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
AfterEach(func() { testServer.Close() }) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, testHandler = testnet.NewServer(reqs) configRepo.SetApiEndpoint(testServer.URL) } Describe(".BindSpace", func() { It("associates the security group with the space", func() { setupTestServer( testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/security_groups/this-is-a-security-group-guid/spaces/yes-its-a-space-guid", Response: testnet.TestResponse{ Status: http.StatusCreated, Body: ` { "metadata": {"guid": "fb6fdf81-ce1b-448f-ada9-09bbb8807812"}, "entity": {"name": "dummy1", "rules": [] } }`, }, })) err := repo.BindSpace("this-is-a-security-group-guid", "yes-its-a-space-guid") Expect(err).ToNot(HaveOccurred()) Expect(testHandler).To(HaveAllRequestsCalled()) }) }) Describe(".UnbindSpace", func() { It("removes the associated security group from the space", func() {
var featureFlagsGetAllRequest = testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/config/feature_flags", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `[ { "name": "user_org_creation", "enabled": false, "error_message": null, "url": "/v2/config/feature_flags/user_org_creation" }, { "name": "private_domain_creation", "enabled": false, "error_message": "foobar", "url": "/v2/config/feature_flags/private_domain_creation" }, { "name": "app_bits_upload", "enabled": true, "error_message": null, "url": "/v2/config/feature_flags/app_bits_upload" }, { "name": "app_scaling", "enabled": true, "error_message": null, "url": "/v2/config/feature_flags/app_scaling" }, { "name": "route_creation", "enabled": true, "error_message": null, "url": "/v2/config/feature_flags/route_creation" } ]`, }, })
AfterEach(func() { testServer.Close() }) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, testHandler = testnet.NewServer(reqs) configRepo.SetApiEndpoint(testServer.URL) } Describe(".Create", func() { It("can create an app security group, given some attributes", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "POST", Path: "/v2/security_groups", // FIXME: this matcher depend on the order of the key/value pairs in the map Matcher: testnet.RequestBodyMatcher(`{ "name": "mygroup", "rules": [{"my-house": "my-rules"}] }`), Response: testnet.TestResponse{Status: http.StatusCreated}, }) setupTestServer(req) err := repo.Create( "mygroup", []map[string]interface{}{{"my-house": "my-rules"}}, ) Expect(err).NotTo(HaveOccurred()) Expect(testHandler).To(HaveAllRequestsCalled()) }) })
app, apiErr := repo.Read("My App") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) Expect(app.Name).To(Equal("My App")) Expect(app.Guid).To(Equal("app1-guid")) Expect(app.Memory).To(Equal(int64(128))) Expect(app.DiskQuota).To(Equal(int64(512))) Expect(app.InstanceCount).To(Equal(1)) Expect(app.EnvironmentVars).To(Equal(map[string]string{"foo": "bar", "baz": "boom"})) Expect(app.Routes[0].Host).To(Equal("app1")) Expect(app.Routes[0].Domain.Name).To(Equal("cfapps.io")) Expect(app.Stack.Name).To(Equal("awesome-stacks-ahoy")) }) It("returns a failure response when the app is not found", func() { request := testapi.NewCloudControllerTestRequest(findAppRequest) request.Response = testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`} ts, handler, repo := createAppRepo([]testnet.TestRequest{request}) defer ts.Close() _, apiErr := repo.Read("My App") Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr.(*errors.ModelNotFoundError)).NotTo(BeNil()) }) }) Describe(".ReadFromSpace", func() { It("returns an application using the given space guid", func() { request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET",
"guid": "service-offering-guid", "label": "cleardb", "provider": "cleardb-provider", "version": "n/a" } } } ] }`, } }) It("gets a summary of services in the given space", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/spaces/my-space-guid/summary", Response: serviceInstanceSummariesResponse, }) ts, handler, repo := createServiceSummaryRepo(req) defer ts.Close() serviceInstances, apiErr := repo.GetSummariesInCurrentSpace() Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) Expect(1).To(Equal(len(serviceInstances))) instance1 := serviceInstances[0] Expect(instance1.Name).To(Equal("my-service-instance")) Expect(instance1.ServicePlan.Name).To(Equal("spark"))
BeforeEach(func() { configRepo = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerServiceAuthTokenRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) Describe("Create", func() { It("creates a service auth token", func() { setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "POST", Path: "/v2/service_auth_tokens", Matcher: testnet.RequestBodyMatcher(`{"label":"a label","provider":"a provider","token":"a token"}`), Response: testnet.TestResponse{Status: http.StatusCreated}, })) err := repo.Create(models.ServiceAuthTokenFields{ Label: "a label", Provider: "a provider", Token: "a token", }) Expect(testHandler).To(HaveAllRequestsCalled()) Expect(err).NotTo(HaveOccurred()) }) }) Describe("FindAll", func() {
AfterEach(func() { testServer.Close() }) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, testHandler = testnet.NewServer(reqs) configRepo.SetApiEndpoint(testServer.URL) } Describe(".BindToRunningSet", func() { It("makes a correct request", func() { setupTestServer( testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/config/running_security_groups/a-real-guid", Response: testnet.TestResponse{ Status: http.StatusCreated, Body: bindRunningResponse, }, }), ) err := repo.BindToRunningSet("a-real-guid") Expect(err).ToNot(HaveOccurred()) Expect(testHandler).To(HaveAllRequestsCalled()) }) }) Describe(".UnbindFromRunningSet", func() { It("makes a correct request", func() { testServer, testHandler = testnet.NewServer([]testnet.TestRequest{
. "github.com/onsi/gomega" ) var _ = Describe("ZonesRepository", func() { Describe("listing zones", func() { It("lists the zones from the the /v2/zones endpoint", func() { firstPageZonesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/zones", Response: testnet.TestResponse{Status: http.StatusOK, Body: `{ "next_url": "/v2/zones?page=2", "resources": [ { "metadata": { "guid": "zone1-guid" }, "entity": { "name": "Zone1", "is_public": true } }, { "metadata": { "guid": "zone2-guid" }, "entity": { "name": "Zone2", "is_public": false, "organization_guid": "org1-guid" } }, { "metadata": { "guid": "zone3-guid" }, "entity": { "name": "Zone3", "is_public": false, "organization_guid": "org2-guid" } } ]}`}, }) secondPageZonesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/zones?page=2", Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [ {
"github.com/nttlabs/cli/cf/net" testconfig "github.com/nttlabs/cli/testhelpers/configuration" testnet "github.com/nttlabs/cli/testhelpers/net" testterm "github.com/nttlabs/cli/testhelpers/terminal" . "github.com/nttlabs/cli/cf/api" . "github.com/nttlabs/cli/testhelpers/matchers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("UserProvidedServiceRepository", func() { It("creates a user provided service with a name and credentials", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "POST", Path: "/v2/user_provided_service_instances", Matcher: testnet.RequestBodyMatcher(`{"name":"my-custom-service","credentials":{"host":"example.com","password":"******","user":"******"},"space_guid":"my-space-guid","syslog_drain_url":""}`), Response: testnet.TestResponse{Status: http.StatusCreated}, }) ts, handler, repo := createUserProvidedServiceInstanceRepo(req) defer ts.Close() apiErr := repo.Create("my-custom-service", "", map[string]interface{}{ "host": "example.com", "user": "******", "password": "******", }) Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred()) })
It("lists all the spaces", func() { firstPageSpacesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/organizations/my-org-guid/spaces?inline-relations-depth=1", Response: testnet.TestResponse{ Status: http.StatusOK, Body: ` { "next_url": "/v2/organizations/my-org-guid/spaces?inline-relations-depth=1&page=2", "resources": [ { "metadata": { "guid": "acceptance-space-guid" }, "entity": { "name": "acceptance", "security_groups": [ { "metadata": { "guid": "4302b3b4-4afc-4f12-ae6d-ed1bb815551f" }, "entity": { "name": "imma-security-group" } } ] } } ] }`}})