本文整理匯總了Golang中github.com/nttlabs/cli/testhelpers/net.NewServer函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewServer函數的具體用法?Golang NewServer怎麽用?Golang NewServer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewServer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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, time.Now, &testterm.FakeUI{})
repo = NewCCUserProvidedServiceInstanceRepository(configRepo, gateway)
return
}
示例2: createServiceBrokerRepo
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, &testterm.FakeUI{})
repo = NewCloudControllerServiceBrokerRepository(configRepo, gateway)
return
}
示例3: 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, time.Now, &testterm.FakeUI{})
repo = NewCloudControllerPasswordRepository(configRepo, gateway)
return
}
示例4: createOrganizationRepo
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, &testterm.FakeUI{})
repo = NewCloudControllerOrganizationRepository(configRepo, gateway)
return
}
示例5: 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(configRepo, time.Now, &testterm.FakeUI{})
repo = NewCloudControllerAppInstancesRepository(configRepo, gateway)
return
}
示例6:
configRepo core_config.ReadWriter
repo RunningSecurityGroupsRepo
)
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
repo = NewRunningSecurityGroupsRepo(configRepo, gateway)
})
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,
},
}),
)
示例7:
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
})
Expect(len(routes)).To(Equal(2))
Expect(routes[0].Guid).To(Equal("route-1-guid"))
示例8:
config.SetAccessToken("BEARER my_access_token")
config.SetApiVersion("2.2.0")
})
JustBeforeEach(func() {
strategy := strategy.NewEndpointStrategy(config.ApiVersion())
gateway := net.NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{})
repo = NewCloudControllerAppEventsRepository(config, gateway, strategy)
})
AfterEach(func() {
server.Close()
})
setupTestServer := func(requests ...testnet.TestRequest) {
server, handler = testnet.NewServer(requests)
config.SetApiEndpoint(server.URL)
}
Describe("list recent events", func() {
It("returns the most recent events", func() {
setupTestServer(eventsRequest)
list, err := repo.RecentEvents("my-app-guid", 2)
Expect(err).ToNot(HaveOccurred())
Expect(list).To(ConsistOf([]models.EventFields{
models.EventFields{
Guid: "event-1-guid",
Name: "audit.app.update",
Timestamp: testtime.MustParse(eventTimestampFormat, "2014-01-21T00:20:11+00:00"),
示例9:
ccGateway := net.NewCloudControllerGateway((config), time.Now, &testterm.FakeUI{})
uaaGateway := net.NewUAAGateway(config, &testterm.FakeUI{})
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",
示例10:
gateway net.Gateway
testServer *httptest.Server
testHandler *testnet.TestHandler
configRepo core_config.ReadWriter
)
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
gateway = net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
repo = NewSecurityGroupSpaceBinder(configRepo, gateway)
})
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": [] }
示例11:
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")
Expect(handler).To(HaveAllRequestsCalled())
Expect(err).ToNot(HaveOccurred())
Expect(list).To(Equal(expectedResponse))
})
})
示例12:
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()
})
It("returns a slice of app summaries for each instance", func() {
apps, apiErr := repo.GetSummariesInCurrentSpace()
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
示例13:
BeforeEach(func() {
config = testconfig.NewRepositoryWithDefaults()
})
JustBeforeEach(func() {
gateway := net.NewCloudControllerGateway((config), time.Now, &testterm.FakeUI{})
strategy := strategy.NewEndpointStrategy(config.ApiVersion())
repo = NewCloudControllerDomainRepository(config, gateway, strategy)
})
AfterEach(func() {
ts.Close()
})
var setupTestServer = func(reqs ...testnet.TestRequest) {
ts, handler = testnet.NewServer(reqs)
config.SetApiEndpoint(ts.URL)
}
Describe("listing domains", func() {
BeforeEach(func() {
config.SetApiVersion("2.2.0")
setupTestServer(firstPagePrivateDomainsRequest, secondPagePrivateDomainsRequest, firstPageSharedDomainsRequest, secondPageSharedDomainsRequest)
})
It("uses the organization-scoped domains endpoints", func() {
receivedDomains := []models.DomainFields{}
apiErr := repo.ListDomainsForOrg("my-org-guid", func(d models.DomainFields) bool {
receivedDomains = append(receivedDomains, d)
return true
})
示例14:
var (
headers string
body string
apiErr error
)
Describe("GET requests", func() {
BeforeEach(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(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
})
It("returns headers with the status code", func() {
Expect(headers).To(ContainSubstring("200"))
})
示例15:
repo CloudControllerBuildpackBitsRepository
buildpack models.Buildpack
testServer *httptest.Server
testServerHandler *testnet.TestHandler
)
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
pwd, _ := os.Getwd()
buildpacksDir = filepath.Join(pwd, "../../fixtures/buildpacks")
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() {