当前位置: 首页>>代码示例>>Golang>>正文


Golang net.RequestBodyMatcher函数代码示例

本文整理汇总了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())
}
开发者ID:nsnt,项目名称:cli,代码行数:34,代码来源:users_test.go

示例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})
}
开发者ID:jalateras,项目名称:cli,代码行数:25,代码来源:routes_test.go

示例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())
}
开发者ID:jalateras,项目名称:cli,代码行数:25,代码来源:service_brokers_test.go

示例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)
}
开发者ID:jalateras,项目名称:cli,代码行数:31,代码来源:buildpacks_test.go

示例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)
}
开发者ID:pmuellr,项目名称:cli,代码行数:33,代码来源:buildpacks_test.go

示例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)
}
开发者ID:jalateras,项目名称:cli,代码行数:32,代码来源:buildpacks_test.go

示例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())
}
开发者ID:nsnt,项目名称:cli,代码行数:25,代码来源:user_provided_service_instances_test.go

示例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)
}
开发者ID:jalateras,项目名称:cli,代码行数:29,代码来源:applications_test.go

示例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())
}
开发者ID:juggernaut,项目名称:cli,代码行数:15,代码来源:services_test.go

示例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())
}
开发者ID:pmuellr,项目名称:cli,代码行数:15,代码来源:service_bindings_test.go

示例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())
}
开发者ID:nsnt,项目名称:cli,代码行数:15,代码来源:spaces_test.go

示例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())
}
开发者ID:nsnt,项目名称:cli,代码行数:15,代码来源:services_test.go

示例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())
}
开发者ID:jalateras,项目名称:cli,代码行数:15,代码来源:spaces_test.go

示例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())
}
开发者ID:pmuellr,项目名称:cli,代码行数:15,代码来源:quotas_test.go

示例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())
}
开发者ID:jalateras,项目名称:cli,代码行数:16,代码来源:organizations_test.go


注:本文中的testhelpers/net.RequestBodyMatcher函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。