func createServiceSummaryRepo(req testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceSummaryRepository) { ts, handler = testnet.NewServer([]testnet.TestRequest{req}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetAPIEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") repo = NewCloudControllerServiceSummaryRepository(configRepo, gateway) return }
func createAppRepo(requests []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ApplicationRepository) { ts, handler = testnet.NewServer(requests) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerApplicationRepository(configRepo, gateway) return }
func createAppRepo(requests []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ApplicationRepository) { ts, handler = testnet.NewServer(requests) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetAPIEndpoint(ts.URL) gateway := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo) repo = NewCloudControllerApplicationRepository(configRepo, gateway) return }
func createServiceBrokerRepo(requests ...testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceBrokerRepository) { ts, handler = testnet.NewServer(requests) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now) repo = NewCloudControllerServiceBrokerRepository(configRepo, gateway) return }
func createServiceSummaryRepo(req testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceSummaryRepository) { ts, handler = testnet.NewServer([]testnet.TestRequest{req}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetAPIEndpoint(ts.URL) gateway := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo) repo = NewCloudControllerServiceSummaryRepository(configRepo, gateway) return }
func createUserProvidedServiceInstanceRepo(req testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo UserProvidedServiceInstanceRepository) { ts, handler = testnet.NewServer([]testnet.TestRequest{req}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now) repo = NewCCUserProvidedServiceInstanceRepository(configRepo, gateway) return }
func createUserProvidedServiceInstanceRepo(req []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo UserProvidedServiceInstanceRepository) { ts, handler = testnet.NewServer(req) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetAPIEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter)) repo = NewCCUserProvidedServiceInstanceRepository(configRepo, gateway) return }
func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo PasswordRepository) { passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetUaaEndpoint(passwordServer.URL) gateway := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo) repo = NewCloudControllerPasswordRepository(configRepo, gateway) return }
func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo Repository) { passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req}) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetUaaEndpoint(passwordServer.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") repo = NewCloudControllerRepository(configRepo, gateway) return }
func createOrganizationRepo(reqs ...testnet.TestRequest) (testserver *httptest.Server, handler *testnet.TestHandler, repo OrganizationRepository) { testserver, handler = testnet.NewServer(reqs) configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(testserver.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now) repo = NewCloudControllerOrganizationRepository(configRepo, gateway) return }
func createAppInstancesRepo(requests []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo Repository) { ts, handler = testnet.NewServer(requests) space := models.SpaceFields{} space.GUID = "my-space-guid" configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetAPIEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") repo = NewCloudControllerAppInstancesRepository(configRepo, gateway) return }
func createAppInstancesRepo(requests []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo AppInstancesRepository) { ts, handler = testnet.NewServer(requests) space := models.SpaceFields{} space.Guid = "my-space-guid" configRepo := testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint(ts.URL) gateway := net.NewCloudControllerGateway(configRepo, time.Now) repo = NewCloudControllerAppInstancesRepository(configRepo, gateway) return }
configRepo coreconfig.ReadWriter repo SecurityGroupsRepo ) BeforeEach(func() { configRepo = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") repo = NewSecurityGroupsRepo(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, testHandler = testnet.NewServer(reqs) configRepo.SetAPIEndpoint(testServer.URL) } Describe("BindToStagingSet", func() { It("makes a correct request", func() { setupTestServer( apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "PUT", Path: "/v2/config/staging_security_groups/a-real-guid", Response: testnet.TestResponse{ Status: http.StatusCreated, Body: bindStagingResponse, }, }), )
}) AfterEach(func() { if ts != nil { ts.Close() } }) Describe("List routes", func() { It("lists routes in the current space", func() { ts, handler = testnet.NewServer([]testnet.TestRequest{ apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/spaces/the-space-guid/routes?inline-relations-depth=1", Response: firstPageRoutesResponse, }), apifakes.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 }) Expect(len(routes)).To(Equal(2)) Expect(routes[0].GUID).To(Equal("route-1-guid"))
gateway := net.NewCloudControllerGateway((configRepo), time.Now) 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 }) Expect(len(routes)).To(Equal(2)) Expect(routes[0].Guid).To(Equal("route-1-guid"))
config configuration.ReadWriter repo BuildpackRepository ) BeforeEach(func() { config = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway((config), time.Now) repo = NewCloudControllerBuildpackRepository(config, gateway) }) AfterEach(func() { ts.Close() }) var setupTestServer = func(requests ...testnet.TestRequest) { ts, handler = testnet.NewServer(requests) config.SetApiEndpoint(ts.URL) } It("lists buildpacks", func() { setupTestServer( testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/buildpacks", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{ "next_url": "/v2/buildpacks?page=2", "resources": [ { "metadata": {
ccGateway := net.NewCloudControllerGateway((config), time.Now) uaaGateway := net.NewUAAGateway(config) repo = NewCloudControllerUserRepository(config, uaaGateway, ccGateway) }) AfterEach(func() { if uaaServer != nil { uaaServer.Close() } if ccServer != nil { ccServer.Close() } }) setupCCServer := func(requests ...testnet.TestRequest) { ccServer, ccHandler = testnet.NewServer(requests) 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",
listFilesServer := httptest.NewServer(http.HandlerFunc(listFilesEndpoint)) defer listFilesServer.Close() req := apifakes.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 := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo) repo := NewCloudControllerAppFilesRepository(configRepo, gateway) list, err := repo.ListFiles("my-app-guid", 1, "some/path") Expect(handler).To(HaveAllRequestsCalled()) Expect(err).ToNot(HaveOccurred()) Expect(list).To(Equal(expectedResponse)) }) })
deps.config = testconfig.NewRepository() deps.config.SetAccessToken("BEARER my_access_token") deps.gateway = net.NewCloudControllerGateway(deps.config, time.Now) return } var _ = Describe("curl command", func() { It("TestCurlGetRequest", func() { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/endpoint", Response: testnet.TestResponse{ Status: http.StatusOK, Body: expectedJSONResponse}, }) ts, handler := testnet.NewServer([]testnet.TestRequest{req}) defer ts.Close() deps := newCurlDependencies() deps.config.SetApiEndpoint(ts.URL) repo := NewCloudControllerCurlRepository(deps.config, deps.gateway) headers, body, apiErr := repo.Request("GET", "/v2/endpoint", "", "") Expect(handler).To(testnet.HaveAllRequestsCalled()) Expect(headers).To(ContainSubstring("200")) Expect(headers).To(ContainSubstring("Content-Type")) Expect(headers).To(ContainSubstring("text/plain")) testassert.JSONStringEquals(body, expectedJSONResponse) Expect(apiErr).NotTo(HaveOccurred()) })
config core_config.ReadWriter auth AuthenticationRepository ) BeforeEach(func() { config = testconfig.NewRepository() gateway = net.NewUAAGateway(config, &testterm.FakeUI{}) auth = NewUAAAuthenticationRepository(gateway, config) }) AfterEach(func() { testServer.Close() }) var setupTestServer = func(request testnet.TestRequest) { testServer, handler = testnet.NewServer([]testnet.TestRequest{request}) config.SetAuthenticationEndpoint(testServer.URL) } Describe("authenticating", func() { var err error JustBeforeEach(func() { err = auth.Authenticate(map[string]string{ "username": "******", "password": "******", }) }) Describe("when login succeeds", func() { BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults() gateway := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo) gateway.PollingThrottle = time.Duration(0) repo = NewCloudControllerApplicationBitsRepository(configRepo, gateway) file1 = resources.AppFileResource{Path: "app.rb", Sha1: "2474735f5163ba7612ef641f438f4b5bee00127b", Size: 51} file2 = resources.AppFileResource{Path: "config.ru", Sha1: "f097424ce1fa66c6cb9f5e8a18c317376ec12e05", Size: 70} file3 = resources.AppFileResource{Path: "Gemfile", Sha1: "d9c3a51de5c89c11331d3b90b972789f1a14699a", Size: 59, Mode: "0750"} file4 = resources.AppFileResource{Path: "Gemfile.lock", Sha1: "345f999aef9070fb9a608e65cf221b7038156b6d", Size: 229, Mode: "0600"} }) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, _ = testnet.NewServer(reqs) configRepo.SetAPIEndpoint(testServer.URL) } Describe(".UploadBits", func() { var uploadFile *os.File var err error BeforeEach(func() { uploadFile, err = os.Open(filepath.Join(fixturesDir, "ignored_and_resource_matched_example_app.zip")) if err != nil { log.Fatal(err) } }) AfterEach(func() {
}) AfterEach(func() { if ts != nil { 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 }) Expect(len(routes)).To(Equal(2)) Expect(routes[0].Guid).To(Equal("route-1-guid"))
AfterEach(func() { testServer.Close() }) Context("error when getting SSH info from /v2/info", func() { BeforeEach(func() { getRequest := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/info", Response: testnet.TestResponse{ Status: http.StatusNotFound, Body: `{}`, }, }) testServer, handler = testnet.NewServer([]testnet.TestRequest{getRequest}) configRepo.SetAPIEndpoint(testServer.URL) ccGateway = net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}, new(tracefakes.FakePrinter), "") deps.Gateways["cloud-controller"] = ccGateway }) It("notifies users", func() { runCommand("my-app") Expect(handler).To(HaveAllRequestsCalled()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Error getting SSH info", "404"}, )) }) })
repo CloudControllerBuildpackBitsRepository buildpack models.Buildpack testServer *httptest.Server testServerHandler *testnet.TestHandler ) BeforeEach(func() { configRepo = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "") pwd, _ := os.Getwd() buildpacksDir = filepath.Join(pwd, "../../fixtures/buildpacks") repo = NewCloudControllerBuildpackBitsRepository(configRepo, gateway, appfiles.ApplicationZipper{}) buildpack = models.Buildpack{Name: "my-cool-buildpack", GUID: "my-cool-buildpack-guid"} testServer, testServerHandler = testnet.NewServer([]testnet.TestRequest{uploadBuildpackRequest()}) configRepo.SetAPIEndpoint(testServer.URL) }) AfterEach(func() { testServer.Close() }) Describe("CreateBuildpackZipFile", func() { Context("when buildpack path is a directory", func() { It("returns an error with an invalid directory", func() { _, _, err := repo.CreateBuildpackZipFile("/foo/bar") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Error opening buildpack file"))
. "github.com/onsi/gomega" "net/http" "net/http/httptest" "time" ) var _ = Describe("Testing with ginkgo", func() { var ( testServer *httptest.Server testHandler *testnet.TestHandler configRepo configuration.ReadWriter repo CloudControllerServiceBindingRepository ) setupTestServer := func(reqs ...testnet.TestRequest) { testServer, testHandler = testnet.NewServer(reqs) configRepo.SetApiEndpoint(testServer.URL) } BeforeEach(func() { configRepo = testconfig.NewRepositoryWithDefaults() gateway := net.NewCloudControllerGateway((configRepo), time.Now) repo = NewCloudControllerServiceBindingRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) Describe("Create", func() {
handler *testnet.TestHandler repo AppSummaryRepository ) Describe("GetSummariesInCurrentSpace()", func() { BeforeEach(func() { getAppSummariesRequest := apifakes.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, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter)) repo = NewCloudControllerAppSummaryRepository(configRepo, gateway) }) AfterEach(func() { testServer.Close() }) It("returns a slice of app summaries for each instance", func() { apps, apiErr := repo.GetSummariesInCurrentSpace() Expect(handler).To(HaveAllRequestsCalled()) Expect(apiErr).NotTo(HaveOccurred())