本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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() {
示例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"))