本文整理匯總了Golang中github.com/nttlabs/cli/cf/api/fakes.NewCloudControllerTestRequest函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCloudControllerTestRequest函數的具體用法?Golang NewCloudControllerTestRequest怎麽用?Golang NewCloudControllerTestRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewCloudControllerTestRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createUsersByRoleEndpoints
func createUsersByRoleEndpoints(rolePath string) (ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) {
nextUrl := rolePath + "?page=2"
ccReqs = []testnet.TestRequest{
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: rolePath,
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: fmt.Sprintf(`
{
"next_url": "%s",
"resources": [
{"metadata": {"guid": "user-1-guid"}, "entity": {}}
]
}`, nextUrl)}}),
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: nextUrl,
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: `
{
"resources": [
{"metadata": {"guid": "user-2-guid"}, "entity": {}},
{"metadata": {"guid": "user-3-guid"}, "entity": {}}
]
}`}}),
}
uaaReqs = []testnet.TestRequest{
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: fmt.Sprintf(
"/Users?attributes=id,userName&filter=%s",
url.QueryEscape(`Id eq "user-1-guid" or Id eq "user-2-guid" or Id eq "user-3-guid"`)),
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: `
{
"resources": [
{ "id": "user-1-guid", "userName": "Super user 1" },
{ "id": "user-2-guid", "userName": "Super user 2" },
{ "id": "user-3-guid", "userName": "Super user 3" }
]
}`}})}
return
}
示例2: deleteSharedDomainReq
func deleteSharedDomainReq(statusCode int) testnet.TestRequest {
return testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "DELETE",
Path: "/v2/shared_domains/my-domain-guid?recursive=true",
Response: testnet.TestResponse{Status: statusCode},
})
}
示例3: 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"
}
}
`},
})
}
示例4: testSpacesDidNotFindByNameWithOrg
func testSpacesDidNotFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", 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())
}
示例5:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AppSummaryRepository", func() {
var (
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()
})
示例6:
}
})
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())
})
示例7: testSpacesFindByNameWithOrg
func testSpacesFindByNameWithOrg(orgGuid string, findByName func(SpaceRepository, string) (models.Space, error)) {
findSpaceByNameResponse := testnet.TestResponse{
Status: http.StatusOK,
Body: `
{
"resources": [
{
"metadata": {
"guid": "space1-guid"
},
"entity": {
"name": "Space1",
"organization_guid": "org1-guid",
"organization": {
"metadata": {
"guid": "org1-guid"
},
"entity": {
"name": "Org1"
}
},
"apps": [
{
"metadata": {
"guid": "app1-guid"
},
"entity": {
"name": "app1"
}
},
{
"metadata": {
"guid": "app2-guid"
},
"entity": {
"name": "app2"
}
}
],
"domains": [
{
"metadata": {
"guid": "domain1-guid"
},
"entity": {
"name": "domain1"
}
}
],
"service_instances": [
{
"metadata": {
"guid": "service1-guid"
},
"entity": {
"name": "service1"
}
}
]
}
}
]
}`}
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: fmt.Sprintf("/v2/organizations/%s/spaces?q=name%%3Aspace1&inline-relations-depth=1", orgGuid),
Response: findSpaceByNameResponse,
})
ts, handler, repo := createSpacesRepo(request)
defer ts.Close()
space, apiErr := findByName(repo, "Space1")
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
Expect(space.Name).To(Equal("Space1"))
Expect(space.Guid).To(Equal("space1-guid"))
Expect(space.Organization.Guid).To(Equal("org1-guid"))
Expect(len(space.Applications)).To(Equal(2))
Expect(space.Applications[0].Guid).To(Equal("app1-guid"))
Expect(space.Applications[1].Guid).To(Equal("app2-guid"))
Expect(len(space.Domains)).To(Equal(1))
Expect(space.Domains[0].Guid).To(Equal("domain1-guid"))
Expect(len(space.ServiceInstances)).To(Equal(1))
Expect(space.ServiceInstances[0].Guid).To(Equal("service1-guid"))
Expect(apiErr).NotTo(HaveOccurred())
return
}
示例8:
)
var _ = Describe("Service Brokers Repo", func() {
It("lists services brokers", func() {
firstRequest := testapi.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 := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/service_brokers?page=2",
示例9:
Name: "the-space-name",
})
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
})
示例10:
. "github.com/nttlabs/cli/testhelpers/matchers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Organization Repository", func() {
Describe("listing organizations", func() {
It("lists the orgs from the the /v2/orgs endpoint", func() {
firstPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
"next_url": "/v2/organizations?page=2",
"resources": [
{
"metadata": { "guid": "org1-guid" },
"entity": { "name": "Org1" }
},
{
"metadata": { "guid": "org2-guid" },
"entity": { "name": "Org2" }
}
]}`},
})
secondPageOrgsRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations?page=2",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
{
"metadata": { "guid": "org3-guid" },
"entity": { "name": "Org3" }
示例11:
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",
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: `{"resources": []}`,
}}),
}
setupCCServer(ccReqs...)
users, apiErr := repo.ListUsersInOrgForRole("my-org-guid", models.ORG_MANAGER)
Expect(ccHandler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
Expect(len(users)).To(Equal(0))
})
})
示例12: createPasswordRepo
"github.com/nttlabs/cli/cf/net"
testconfig "github.com/nttlabs/cli/testhelpers/configuration"
testnet "github.com/nttlabs/cli/testhelpers/net"
testterm "github.com/nttlabs/cli/testhelpers/terminal"
. "github.com/nttlabs/cli/cf/api/password"
. "github.com/nttlabs/cli/testhelpers/matchers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("CloudControllerPasswordRepository", func() {
It("updates your password", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/Users/my-user-guid/password",
Matcher: testnet.RequestBodyMatcher(`{"password":"new-password","oldPassword":"old-password"}`),
Response: testnet.TestResponse{Status: http.StatusOK},
})
passwordUpdateServer, handler, repo := createPasswordRepo(req)
defer passwordUpdateServer.Close()
apiErr := repo.UpdatePassword("old-password", "new-password")
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
})
})
func createPasswordRepo(req testnet.TestRequest) (passwordServer *httptest.Server, handler *testnet.TestHandler, repo PasswordRepository) {
passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req})
示例13:
writer.WriteHeader(http.StatusInternalServerError)
return
}
writer.WriteHeader(http.StatusOK)
fmt.Fprint(writer, expectedResponse)
}
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")
示例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 domain by name", func() {
setupTestServer(testapi.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.FindByName("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"))
})
示例15:
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(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/service_plans/my-service-plan-guid",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-service-plan", "free":true, "description":"descriptive text", "public":true, "service_guid":"service-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
}))
})
It("Updates the service to public", 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())