當前位置: 首頁>>代碼示例>>Golang>>正文


Golang apifakes.NewCloudControllerTestRequest函數代碼示例

本文整理匯總了Golang中code/cloudfoundry/org/cli/cf/api/apifakes.NewCloudControllerTestRequest函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCloudControllerTestRequest函數的具體用法?Golang NewCloudControllerTestRequest怎麽用?Golang NewCloudControllerTestRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewCloudControllerTestRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deleteSharedDomainReq

func deleteSharedDomainReq(statusCode int) testnet.TestRequest {
	return apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "DELETE",
		Path:     "/v2/shared_domains/my-domain-guid?recursive=true",
		Response: testnet.TestResponse{Status: statusCode},
	})
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:7,代碼來源:domains_test.go

示例2: uploadApplicationRequest

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"
	}
}
	`},
	})
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:17,代碼來源:application_bits_test.go

示例3: testSpacesDidNotFindByNameWithOrg

func testSpacesDidNotFindByNameWithOrg(orgGUID string, findByName func(SpaceRepository, string) (models.Space, error)) {
	request := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1", 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())
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:18,代碼來源:spaces_test.go

示例4:

	testnet "code.cloudfoundry.org/cli/testhelpers/net"

	. "code.cloudfoundry.org/cli/cf/api"
	"code.cloudfoundry.org/cli/cf/trace/tracefakes"
	. "code.cloudfoundry.org/cli/testhelpers/matchers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("UserProvidedServiceRepository", func() {

	Context("Create()", func() {
		It("creates a user provided service with a name and credentials", func() {
			req := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "POST",
				Path:     "/v2/user_provided_service_instances",
				Matcher:  testnet.RequestBodyMatcher(`{"name":"my-custom-service","credentials":{"host":"example.com","password":"secret","user":"me"},"space_guid":"my-space-guid","syslog_drain_url":"","route_service_url":""}`),
				Response: testnet.TestResponse{Status: http.StatusCreated},
			})

			ts, handler, repo := createUserProvidedServiceInstanceRepo([]testnet.TestRequest{req})
			defer ts.Close()

			apiErr := repo.Create("my-custom-service", "", "", map[string]interface{}{
				"host":     "example.com",
				"user":     "me",
				"password": "secret",
			})
			Expect(handler).To(HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())
		})
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:user_provided_service_instances_test.go

示例5:

		ts, handler = testnet.NewServer(requests)
		config.SetAPIEndpoint(ts.URL)
	}

	It("lists buildpacks", func() {
		setupTestServer(
			apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method: "GET",
				Path:   "/v2/buildpacks",
				Response: testnet.TestResponse{
					Status: http.StatusOK,
					Body: `{
					  "next_url": "/v2/buildpacks?page=2",
					  "resources": [
						{
						  "metadata": {
							"guid": "buildpack1-guid"
						  },
						  "entity": {
							"name": "Buildpack1",
							"position" : 1,
							"filename" : "firstbp.zip"
						  }
						}
					  ]
					}`}}),
			apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method: "GET",
				Path:   "/v2/buildpacks?page=2",
				Response: testnet.TestResponse{
					Status: http.StatusOK,
					Body: `{
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:32,代碼來源:buildpacks_test.go

示例6:

		Describe("Error getting required info to run ssh", func() {
			var (
				testServer *httptest.Server
				handler    *testnet.TestHandler
			)

			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(
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:32,代碼來源:ssh_test.go

示例7:

		gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "")
		repo = NewCloudControllerServiceRepository(configRepo, gateway)
	})

	AfterEach(func() {
		if testServer != nil {
			testServer.Close()
		}
	})

	Describe("GetAllServiceOfferings", func() {
		BeforeEach(func() {
			setupTestServer(
				apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/services",
					Response: firstOfferingsResponse,
				}),
				apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "GET",
					Path:     "/v2/services",
					Response: multipleOfferingsResponse,
				}),
			)
		})

		It("gets all public service offerings", func() {
			offerings, err := repo.GetAllServiceOfferings()

			Expect(testHandler).To(HaveAllRequestsCalled())
			Expect(err).NotTo(HaveOccurred())
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:services_test.go

示例8:

		gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter), "")
		repo = NewCloudControllerRouteRepository(configRepo, gateway)
	})

	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
			})
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:routes_test.go

示例9:

)

var _ = Describe("Service Brokers Repo", func() {
	It("lists services brokers", func() {
		firstRequest := apifakes.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": "found-username-1",
						"auth_password": "found-password-1"
					  }
					}
				  ]
				}`,
			},
		})

		secondRequest := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
			Method: "GET",
			Path:   "/v2/service_brokers?page=2",
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:service_brokers_test.go

示例10:

			}
		})

		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())
		})
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:30,代碼來源:application_bits_test.go

示例11:

	. "github.com/onsi/gomega"
)

var _ = Describe("AppSummaryRepository", func() {
	var (
		testServer *httptest.Server
		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()
		})
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:app_summary_test.go

示例12:

								"guid": "service-offering-guid",
								"label": "cleardb",
								"provider": "cleardb-provider",
								"version": "n/a"
							}
					  }
					}
			  ]
			}`,
		}
	})

	It("gets a summary of services in the given space", func() {
		req := apifakes.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.LastOperation.Type).To(Equal("create"))
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:service_summary_test.go

示例13:

				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(apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "PUT",
				Path:     "/v2/service_plans/my-service-plan-guid",
				Matcher:  testnet.RequestBodyMatcher(`{"public":true}`),
				Response: testnet.TestResponse{Status: http.StatusCreated},
			}))
		})

		It("updates public on the service to whatever is passed", 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())
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:32,代碼來源:service_plan_test.go

示例14:

		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 shared domain by name", func() {
		setupTestServer(apifakes.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.FindSharedByName("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(domain.Shared).To(BeTrue())
	})
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:domains_test.go

示例15:

			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]interface{}{"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 := apifakes.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(".GetApp", func() {
		It("returns an application using the given app guid", func() {
			request := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "GET",
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:31,代碼來源:applications_test.go


注:本文中的code/cloudfoundry/org/cli/cf/api/apifakes.NewCloudControllerTestRequest函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。