本文整理汇总了Golang中testhelpers/api.NewCloudControllerTestRequest函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCloudControllerTestRequest函数的具体用法?Golang NewCloudControllerTestRequest怎么用?Golang NewCloudControllerTestRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCloudControllerTestRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testSetOrUnsetSpaceRoleWithValidRole
func testSetOrUnsetSpaceRoleWithValidRole(t *testing.T,
setOrUnset func(UserRepository, cf.User, cf.Space) net.ApiResponse,
verb string,
path string) {
reqs := []testnet.TestRequest{}
if verb == "PUT" {
addToOrgReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/organizations/my-space-org-guid/users/my-user-guid",
Response: testnet.TestResponse{Status: http.StatusOK},
})
reqs = append(reqs, addToOrgReq)
}
setOrUnsetReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: verb,
Path: path,
Response: testnet.TestResponse{Status: http.StatusOK},
})
reqs = append(reqs, setOrUnsetReq)
cc, handler, repo := createUsersRepoWithoutUAAEndpoints(t, reqs)
defer cc.Close()
user := cf.User{Guid: "my-user-guid"}
space := cf.Space{Guid: "my-space-guid", Organization: cf.Organization{Guid: "my-space-org-guid"}}
apiResponse := setOrUnset(repo, user, space)
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
}
示例2: TestCreateUser
func TestCreateUser(t *testing.T) {
ccReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/users",
Matcher: testnet.RequestBodyMatcher(`{"guid":"my-user-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
uaaReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/Users",
Matcher: testnet.RequestBodyMatcher(`{
"userName":"my-user",
"emails":[{"value":"my-user"}],
"password":"my-password",
"name":{
"givenName":"my-user",
"familyName":"my-user"}
}`),
Response: testnet.TestResponse{
Status: http.StatusCreated,
Body: `{"id":"my-user-guid"}`,
},
})
cc, ccHandler, uaa, uaaHandler, repo := createUsersRepo(t, []testnet.TestRequest{ccReq}, []testnet.TestRequest{uaaReq})
defer cc.Close()
defer uaa.Close()
apiResponse := repo.Create("my-user", "my-password")
assert.True(t, ccHandler.AllRequestsCalled())
assert.True(t, uaaHandler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例3: TestDomainFindByNameInCurrentSpaceWhenFoundInDomainsButNotShared
func TestDomainFindByNameInCurrentSpaceWhenFoundInDomainsButNotShared(t *testing.T) {
spaceDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/spaces/my-space-guid/domains?q=name%3Adomain2.cf-app.com",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`},
})
sharedDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/domains?q=name%3Adomain2.cf-app.com",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": [
{
"metadata": { "guid": "some-domain-guid" },
"entity": {
"name": "some.cf-app.com",
"owning_organization_guid": "some-org-guid"
}
}
]}`},
})
ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{spaceDomainsReq, sharedDomainsReq})
defer ts.Close()
_, apiResponse := repo.FindByNameInCurrentSpace("domain2.cf-app.com")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsError())
assert.True(t, apiResponse.IsNotFound())
}
示例4: TestDomainFindByNameInOrgWhenFoundInDomainsButNotShared
func TestDomainFindByNameInOrgWhenFoundInDomainsButNotShared(t *testing.T) {
orgDomainsReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations/my-org-guid/domains?inline-relations-depth=1&q=name%3Adomain2.cf-app.com",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{"resources": []}`},
})
sharedDomainsReq := 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": "shared-domain-guid" },
"entity": {
"name": "shared-example.com",
"owning_organization_guid": "some-other-org-guid",
"wildcard": true,
"spaces": []
}
}
]}`},
})
ts, handler, repo := createDomainRepo(t, []testnet.TestRequest{orgDomainsReq, sharedDomainsReq})
defer ts.Close()
_, apiResponse := repo.FindByNameInOrg("domain2.cf-app.com", "my-org-guid")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsError())
assert.True(t, apiResponse.IsNotFound())
}
示例5: TestRoutesListRoutes
func TestRoutesListRoutes(t *testing.T) {
firstRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/routes?inline-relations-depth=1",
Response: firstPageRoutesResponse,
})
secondRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/routes?inline-relations-depth=1&page=2",
Response: secondPageRoutesResponse,
})
ts, handler, repo, _ := createRoutesRepo(t, firstRequest, secondRequest)
defer ts.Close()
stopChan := make(chan bool)
defer close(stopChan)
routesChan, statusChan := repo.ListRoutes(stopChan)
routes := []cf.Route{}
for chunk := range routesChan {
routes = append(routes, chunk...)
}
apiResponse := <-statusChan
assert.Equal(t, len(routes), 2)
assert.Equal(t, routes[0].Guid, "route-1-guid")
assert.Equal(t, routes[1].Guid, "route-2-guid")
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
}
示例6: TestSpacesListSpaces
func TestSpacesListSpaces(t *testing.T) {
firstPageSpacesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations/some-org-guid/spaces",
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: `{
"next_url": "/v2/organizations/some-org-guid/spaces?page=2",
"resources": [
{
"metadata": {
"guid": "acceptance-space-guid"
},
"entity": {
"name": "acceptance"
}
}
]
}`}})
secondPageSpacesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations/some-org-guid/spaces?page=2",
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: `{
"resources": [
{
"metadata": {
"guid": "staging-space-guid"
},
"entity": {
"name": "staging"
}
}
]
}`}})
ts, handler, repo := createSpacesRepo(t, firstPageSpacesRequest, secondPageSpacesRequest)
defer ts.Close()
stopChan := make(chan bool)
defer close(stopChan)
spacesChan, statusChan := repo.ListSpaces(stopChan)
spaces := []cf.Space{}
for chunk := range spacesChan {
spaces = append(spaces, chunk...)
}
apiResponse := <-statusChan
assert.Equal(t, spaces[0].Guid, "acceptance-space-guid")
assert.Equal(t, spaces[1].Guid, "staging-space-guid")
assert.True(t, apiResponse.IsSuccessful())
assert.True(t, handler.AllRequestsCalled())
}
示例7: TestOrganizationPaginator
func TestOrganizationPaginator(t *testing.T) {
firstReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
"total_pages": 2,
"next_url": "/v2/organizations?page=2",
"resources": [
{
"metadata": { "guid": "org1-guid" },
"entity": { "name": "Org1" }
}
]}`},
})
secondReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/organizations?page=2",
Response: testnet.TestResponse{Status: http.StatusOK, Body: `{
"total_pages": 2,
"next_url": "",
"resources": [
{
"metadata": { "guid": "org2-guid" },
"entity": { "name": "Org2" }
}
]}`},
})
ts, handler, p := createOrgPaginator(t, firstReq, secondReq)
defer ts.Close()
assert.True(t, p.HasNext())
firstChunk, apiResponse := p.Next()
assert.True(t, apiResponse.IsSuccessful())
assert.Equal(t, len(firstChunk), 1)
firstOutput := firstChunk[0]
assert.Contains(t, firstOutput, "Org1")
assert.True(t, p.HasNext())
secondChunk, apiResponse := p.Next()
assert.True(t, apiResponse.IsSuccessful())
assert.Equal(t, len(secondChunk), 1)
secondOutput := secondChunk[0]
assert.Contains(t, secondOutput, "Org2")
assert.False(t, p.HasNext())
assert.True(t, handler.AllRequestsCalled())
}
示例8: createUsersByRoleEndpoints
func createUsersByRoleEndpoints(rolePath string) (ccReqs []testnet.TestRequest, uaaReqs []testnet.TestRequest) {
nextUrl := rolePath + "?page=2"
req := 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)},
})
secondReq := 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": {}} ]
}`},
})
ccReqs = append(ccReqs, req, secondReq)
uaaRoleResponses := []string{
`{ "resources": [ { "id": "user-1-guid", "userName": "Super user 1" }]}`,
`{ "resources": [
{ "id": "user-2-guid", "userName": "Super user 2" },
{ "id": "user-3-guid", "userName": "Super user 3" }
]}`,
}
filters := []string{
`Id eq "user-1-guid"`,
`Id eq "user-2-guid" or Id eq "user-3-guid"`,
}
for index, resp := range uaaRoleResponses {
path := fmt.Sprintf(
"/Users?attributes=id,userName&filter=%s",
url.QueryEscape(filters[index]),
)
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: path,
Response: testnet.TestResponse{Status: http.StatusOK, Body: resp},
})
uaaReqs = append(uaaReqs, req)
}
return
}
示例9: 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
}
示例10: TestOrganizationsListOrgs
func TestOrganizationsListOrgs(t *testing.T) {
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" }
}
]}`},
})
ts, handler, repo := createOrganizationRepo(t, firstPageOrgsRequest, secondPageOrgsRequest)
defer ts.Close()
stopChan := make(chan bool)
defer close(stopChan)
orgsChan, statusChan := repo.ListOrgs(stopChan)
orgs := []cf.Organization{}
for chunk := range orgsChan {
orgs = append(orgs, chunk...)
}
apiResponse := <-statusChan
assert.Equal(t, len(orgs), 3)
assert.Equal(t, orgs[0].Guid, "org1-guid")
assert.Equal(t, orgs[1].Guid, "org2-guid")
assert.Equal(t, orgs[2].Guid, "org3-guid")
assert.True(t, apiResponse.IsSuccessful())
assert.True(t, handler.AllRequestsCalled())
}
示例11: TestStopApplication
func TestStopApplication(t *testing.T) {
stopApplicationRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/apps/my-cool-app-guid?inline-relations-depth=2",
Matcher: testnet.RequestBodyMatcher(`{"console":true,"state":"STOPPED"}`),
Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
"metadata": {
"guid": "my-updated-app-guid"
},
"entity": {
"name": "cli1",
"state": "STOPPED"
}
}`},
})
ts, handler, repo := createAppRepo(t, []testnet.TestRequest{stopApplicationRequest})
defer ts.Close()
app := cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"}
updatedApp, apiResponse := repo.Stop(app)
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
assert.Equal(t, "cli1", updatedApp.Name)
assert.Equal(t, "stopped", updatedApp.State)
assert.Equal(t, "my-updated-app-guid", updatedApp.Guid)
}
示例12: TestGetInstances
func TestGetInstances(t *testing.T) {
getInstancesRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/apps/my-cool-app-guid/instances",
Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
"1": {
"state": "STARTING"
},
"0": {
"state": "RUNNING"
}
}`},
})
ts, handler, repo := createAppRepo(t, []testnet.TestRequest{getInstancesRequest})
defer ts.Close()
app := cf.Application{Name: "my-cool-app", Guid: "my-cool-app-guid"}
instances, apiResponse := repo.GetInstances(app)
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
assert.Equal(t, len(instances), 2)
assert.Equal(t, instances[0].State, "running")
assert.Equal(t, instances[1].State, "starting")
}
示例13: TestCreateBuildpackEnabled
func TestCreateBuildpackEnabled(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/buildpacks",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":999, "enabled":true}`),
Response: testnet.TestResponse{
Status: http.StatusCreated,
Body: `{
"metadata": {
"guid": "my-cool-buildpack-guid"
},
"entity": {
"name": "my-cool-buildpack",
"position":999,
"enabled":true
}
}`},
})
ts, handler, repo := createBuildpackRepo(t, req)
defer ts.Close()
position := 999
enabled := true
created, apiResponse := repo.Create("my-cool-buildpack", &position, &enabled)
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
assert.NotNil(t, created.Guid)
assert.Equal(t, "my-cool-buildpack", created.Name)
assert.Equal(t, 999, *created.Position)
}
示例14: 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},
})
}
示例15: unmapDomainReq
func unmapDomainReq(statusCode int) testnet.TestRequest {
return testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "DELETE",
Path: "/v2/spaces/my-space-guid/domains/my-domain-guid",
Response: testnet.TestResponse{Status: statusCode},
})
}