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


Golang net.NewServer函數代碼示例

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


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

示例1: testUploadApp

func testUploadApp(dir string, requests []testnet.TestRequest) (app models.Application, apiErr errors.Error) {
	ts, handler := testnet.NewServer(requests)
	defer ts.Close()

	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway(configRepo)
	gateway.PollingThrottle = time.Duration(0)
	zipper := app_files.ApplicationZipper{}
	repo := NewCloudControllerApplicationBitsRepository(configRepo, gateway, zipper)

	var (
		reportedPath                          string
		reportedFileCount, reportedUploadSize uint64
	)
	apiErr = repo.UploadApp("my-cool-app-guid", dir, func(path string, uploadSize, fileCount uint64) {
		reportedPath = path
		reportedUploadSize = uploadSize
		reportedFileCount = fileCount
	})

	Expect(reportedPath).To(Equal(dir))
	Expect(reportedFileCount).To(Equal(uint64(len(expectedApplicationContent))))
	Expect(reportedUploadSize).To(Equal(uint64(759)))
	Expect(handler).To(testnet.HaveAllRequestsCalled())

	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:28,代碼來源:application_bits_test.go

示例2: setupAuthDependencies

func setupAuthDependencies(request testnet.TestRequest) (*httptest.Server, *testnet.TestHandler, configuration.ReadWriter) {
	ts, handler := testnet.NewServer([]testnet.TestRequest{request})
	config := testconfig.NewRepository()
	config.SetAuthenticationEndpoint(ts.URL)

	return ts, handler, config
}
開發者ID:knolleary,項目名稱:cli,代碼行數:7,代碼來源:authentication_test.go

示例3: createUserProvidedServiceInstanceRepo

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)
	repo = NewCCUserProvidedServiceInstanceRepository(configRepo, gateway)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:8,代碼來源:user_provided_service_instances_test.go

示例4: createServiceRepoWithConfig

func createServiceRepoWithConfig(reqs []testnet.TestRequest, config configuration.ReadWriter) (testServer *httptest.Server, handler *testnet.TestHandler, repo ServiceRepository) {
	testServer, handler = testnet.NewServer(reqs)
	config.SetApiEndpoint(testServer.URL)

	gateway := net.NewCloudControllerGateway(config)
	repo = NewCloudControllerServiceRepository(config, gateway)
	return
}
開發者ID:juggernaut,項目名稱:cli,代碼行數:8,代碼來源:services_test.go

示例5: createDomainRepo

func createDomainRepo(reqs []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo DomainRepository) {
	ts, handler = testnet.NewServer(reqs)
	config := testconfig.NewRepositoryWithDefaults()
	config.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway()
	repo = NewCloudControllerDomainRepository(config, gateway)
	return
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:8,代碼來源:domains_test.go

示例6: createServiceBindingRepo

func createServiceBindingRepo(requests []testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo ServiceBindingRepository) {
	ts, handler = testnet.NewServer(requests)
	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway()
	repo = NewCloudControllerServiceBindingRepository(configRepo, gateway)
	return
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:8,代碼來源:service_bindings_test.go

示例7: createOrganizationRepo

func createOrganizationRepo(reqs ...testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo OrganizationRepository) {
	ts, handler = testnet.NewServer(reqs)

	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway(configRepo)
	repo = NewCloudControllerOrganizationRepository(configRepo, gateway)
	return
}
開發者ID:julz,項目名稱:cli,代碼行數:9,代碼來源:organizations_test.go

示例8: createPasswordRepo

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 := net.NewCloudControllerGateway(configRepo)
	repo = NewCloudControllerPasswordRepository(configRepo, gateway)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:9,代碼來源:password_test.go

示例9: createAppInstancesRepo

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()
	repo = NewCloudControllerAppInstancesRepository(configRepo, gateway)
	return
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:10,代碼來源:app_instances_test.go

示例10: createPasswordRepo

func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo PasswordRepository) {
	passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req})

	endpointRepo := &testapi.FakeEndpointRepo{}
	endpointRepo.UAAEndpointReturns.Endpoint = passwordServer.URL
	configRepo := testconfig.NewRepositoryWithDefaults()
	gateway := net.NewCloudControllerGateway()
	repo = NewCloudControllerPasswordRepository(configRepo, gateway, endpointRepo)
	return
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:10,代碼來源:password_test.go

示例11: createRoutesRepo

func createRoutesRepo(requests ...testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo CloudControllerRouteRepository, domainRepo *testapi.FakeDomainRepository) {
	ts, handler = testnet.NewServer(requests)

	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ts.URL)
	gateway := net.NewCloudControllerGateway(configRepo)
	domainRepo = &testapi.FakeDomainRepository{}

	repo = NewCloudControllerRouteRepository(configRepo, gateway, domainRepo)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:11,代碼來源:routes_test.go

示例12: setupEventTest

func setupEventTest(requests []testnet.TestRequest) (deps eventTestDependencies) {
	deps.server, deps.handler = testnet.NewServer(requests)

	configRepo := testconfig.NewRepository()
	configRepo.SetApiEndpoint(deps.server.URL)
	configRepo.SetAccessToken("BEARER my_access_token")

	deps.config = configRepo
	deps.gateway = net.NewCloudControllerGateway()

	return
}
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:12,代碼來源:app_events_test.go

示例13: createUsersRepo

func createUsersRepo(ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) (cc *httptest.Server,
	ccHandler *testnet.TestHandler, uaa *httptest.Server, uaaHandler *testnet.TestHandler, repo UserRepository) {

	ccTarget := ""
	uaaTarget := ""

	if len(ccReqs) > 0 {
		cc, ccHandler = testnet.NewServer(ccReqs)
		ccTarget = cc.URL
	}
	if len(uaaReqs) > 0 {
		uaa, uaaHandler = testnet.NewServer(uaaReqs)
		uaaTarget = uaa.URL
	}

	configRepo := testconfig.NewRepositoryWithDefaults()
	configRepo.SetApiEndpoint(ccTarget)
	ccGateway := net.NewCloudControllerGateway(configRepo)
	uaaGateway := net.NewUAAGateway(configRepo)
	configRepo.SetUaaEndpoint(uaaTarget)
	repo = NewCloudControllerUserRepository(configRepo, uaaGateway, ccGateway)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:23,代碼來源:users_test.go

示例14:

		repo              CloudControllerBuildpackBitsRepository
		buildpack         models.Buildpack
		testServer        *httptest.Server
		testServerHandler *testnet.TestHandler
	)

	BeforeEach(func() {
		gateway := net.NewCloudControllerGateway(configRepo)
		pwd, _ := os.Getwd()

		buildpacksDir = filepath.Join(pwd, "../../fixtures/buildpacks")
		configRepo = testconfig.NewRepositoryWithDefaults()
		repo = NewCloudControllerBuildpackBitsRepository(configRepo, gateway, app_files.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("#UploadBuildpack", func() {
		It("fails to upload a buildpack with an invalid directory", func() {
			apiErr := repo.UploadBuildpack(buildpack, "/foo/bar")
			Expect(apiErr).NotTo(BeNil())
			Expect(apiErr.Error()).To(ContainSubstring("Error opening buildpack file"))
		})

		It("uploads a valid buildpack directory", func() {
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:buildpack_bits_test.go

示例15:

		domainRepo = &testapi.FakeDomainRepository{}
		repo = NewCloudControllerRouteRepository(configRepo, gateway, domainRepo)
	})

	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"))
開發者ID:nota-ja,項目名稱:cli,代碼行數:32,代碼來源:routes_test.go


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