本文整理汇总了Golang中testhelpers/net.RequestBodyMatcher函数的典型用法代码示例。如果您正苦于以下问题:Golang RequestBodyMatcher函数的具体用法?Golang RequestBodyMatcher怎么用?Golang RequestBodyMatcher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RequestBodyMatcher函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
示例2: TestCreateInSpace
func TestCreateInSpace(t *testing.T) {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/routes",
Matcher: testnet.RequestBodyMatcher(`{"host":"my-cool-app","domain_guid":"my-domain-guid","space_guid":"my-space-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
"metadata": { "guid": "my-route-guid" },
"entity": { "host": "my-cool-app" }
}`},
})
ts, handler, repo, _ := createRoutesRepo(t, request)
defer ts.Close()
domain := cf.Domain{Guid: "my-domain-guid"}
newRoute := cf.Route{Host: "my-cool-app"}
space := cf.Space{Guid: "my-space-guid"}
createdRoute, apiResponse := repo.CreateInSpace(newRoute, domain, space)
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
assert.Equal(t, createdRoute, cf.Route{Host: "my-cool-app", Guid: "my-route-guid", Domain: domain})
}
示例3: TestUpdateServiceBroker
func TestUpdateServiceBroker(t *testing.T) {
expectedReqBody := `{"broker_url":"http://update.example.com","auth_username":"update-foouser","auth_password":"update-password"}`
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/service_brokers/my-guid",
Matcher: testnet.RequestBodyMatcher(expectedReqBody),
Response: testnet.TestResponse{Status: http.StatusOK},
})
ts, handler, repo := createServiceBrokerRepo(t, req)
defer ts.Close()
serviceBroker := cf.ServiceBroker{
Guid: "my-guid",
Name: "foobroker",
Url: "http://update.example.com",
Username: "update-foouser",
Password: "update-password",
}
apiResponse := repo.Update(serviceBroker)
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
}
示例4: TestUpdateBuildpack
func TestUpdateBuildpack(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/buildpacks/my-cool-buildpack-guid",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":555}`),
Response: testnet.TestResponse{
Status: http.StatusCreated,
Body: `{
"metadata": {
"guid": "my-cool-buildpack-guid"
},
"entity": {
"name": "my-cool-buildpack",
"position":555
}
}`},
})
ts, handler, repo := createBuildpackRepo(t, []testnet.TestRequest{req})
defer ts.Close()
position := 555
buildpack := cf.Buildpack{Name: "my-cool-buildpack", Guid: "my-cool-buildpack-guid", Position: &position}
updated, apiResponse := repo.Update(buildpack)
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
assert.Equal(t, buildpack, updated)
}
示例5: 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)
}
示例6: TestCreateBuildpackWithPosition
func TestCreateBuildpackWithPosition(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/buildpacks",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-buildpack","position":999}`),
Response: testnet.TestResponse{
Status: http.StatusCreated,
Body: `{
"metadata": {
"guid": "my-cool-buildpack-guid"
},
"entity": {
"name": "my-cool-buildpack",
"position":999
}
}`},
})
ts, handler, repo := createBuildpackRepo(t, []testnet.TestRequest{req})
defer ts.Close()
position := 999
buildpack := cf.Buildpack{Name: "my-cool-buildpack", Position: &position}
created, apiResponse := repo.Create(buildpack)
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
assert.NotNil(t, created.Guid)
assert.Equal(t, buildpack.Name, created.Name)
assert.Equal(t, *buildpack.Position, 999)
}
示例7: TestUpdateUserProvidedServiceInstance
func TestUpdateUserProvidedServiceInstance(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/user_provided_service_instances/my-instance-guid",
Matcher: testnet.RequestBodyMatcher(`{"credentials":{"host":"example.com","password":"secret","user":"me"},"syslog_drain_url":"syslog://example.com"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createUserProvidedServiceInstanceRepo(t, req)
defer ts.Close()
params := map[string]string{
"host": "example.com",
"user": "me",
"password": "secret",
}
serviceInstance := cf.ServiceInstanceFields{}
serviceInstance.Guid = "my-instance-guid"
serviceInstance.Params = params
serviceInstance.SysLogDrainUrl = "syslog://example.com"
apiResponse := repo.Update(serviceInstance)
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例8: 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)
}
示例9: testRenameService
func testRenameService(endpointPath string, serviceInstance models.ServiceInstance) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: endpointPath,
Matcher: testnet.RequestBodyMatcher(`{"name":"new-name"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
testServer, handler, repo := createServiceRepo([]testnet.TestRequest{req})
defer testServer.Close()
apiErr := repo.RenameService(serviceInstance, "new-name")
Expect(handler).To(testnet.HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
}
示例10: TestCreateServiceBinding
func TestCreateServiceBinding(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/service_bindings",
Matcher: testnet.RequestBodyMatcher(`{"app_guid":"my-app-guid","service_instance_guid":"my-service-instance-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createServiceBindingRepo(t, []testnet.TestRequest{req})
defer ts.Close()
apiResponse := repo.Create("my-service-instance-guid", "my-app-guid")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例11: TestRenameSpace
func TestRenameSpace(t *testing.T) {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/spaces/my-space-guid",
Matcher: testnet.RequestBodyMatcher(`{"name":"new-space-name"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createSpacesRepo(t, request)
defer ts.Close()
apiResponse := repo.Rename("my-space-guid", "new-space-name")
assert.True(t, handler.AllRequestsCalled())
assert.True(t, apiResponse.IsSuccessful())
}
示例12: testRenameService
func testRenameService(t *testing.T, endpointPath string, serviceInstance cf.ServiceInstance) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: endpointPath,
Matcher: testnet.RequestBodyMatcher(`{"name":"new-name"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createServiceRepo(t, []testnet.TestRequest{req})
defer ts.Close()
apiResponse := repo.RenameService(serviceInstance, "new-name")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例13: TestCreateSpace
func TestCreateSpace(t *testing.T) {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/spaces",
Matcher: testnet.RequestBodyMatcher(`{"name":"space-name","organization_guid":"some-org-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createSpacesRepo(t, request)
defer ts.Close()
apiResponse := repo.Create("space-name")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例14: TestUpdateQuota
func TestUpdateQuota(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/organizations/my-org-guid",
Matcher: testnet.RequestBodyMatcher(`{"quota_definition_guid":"my-quota-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createQuotaRepo(t, req)
defer ts.Close()
apiResponse := repo.Update("my-org-guid", "my-quota-guid")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}
示例15: TestRenameOrganization
func TestRenameOrganization(t *testing.T) {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/organizations/my-org-guid",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-new-org"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createOrganizationRepo(t, req)
defer ts.Close()
org := cf.Organization{Guid: "my-org-guid"}
apiResponse := repo.Rename(org, "my-new-org")
assert.True(t, handler.AllRequestsCalled())
assert.False(t, apiResponse.IsNotSuccessful())
}