本文整理汇总了Golang中github.com/cloudfoundry/cli/testhelpers/net.RequestBodyMatcher函数的典型用法代码示例。如果您正苦于以下问题:Golang RequestBodyMatcher函数的具体用法?Golang RequestBodyMatcher怎么用?Golang RequestBodyMatcher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RequestBodyMatcher函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
})
setupTestServer := func(reqs ...testnet.TestRequest) {
testServer, testHandler = testnet.NewServer(reqs)
configRepo.SetApiEndpoint(testServer.URL)
}
Describe(".Create", func() {
It("can create an app security group, given some attributes", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/security_groups",
// FIXME: this matcher depend on the order of the key/value pairs in the map
Matcher: testnet.RequestBodyMatcher(`{
"name": "mygroup",
"rules": [{"my-house": "my-rules"}],
"space_guids": ["myspace"]
}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
setupTestServer(req)
err := repo.Create(
"mygroup",
[]map[string]string{{"my-house": "my-rules"}},
[]string{"myspace"},
)
Expect(err).NotTo(HaveOccurred())
Expect(testHandler).To(HaveAllRequestsCalled())
})
示例2:
}`,
}})
one := 1
createdBuildpack, apiErr := repo.Create("name with space", &one, nil, nil)
Expect(apiErr).To(HaveOccurred())
Expect(createdBuildpack).To(Equal(models.Buildpack{}))
Expect(apiErr.(errors.HttpError).ErrorCode()).To(Equal("290003"))
Expect(apiErr.Error()).To(ContainSubstring("Buildpack is invalid"))
})
It("sets the position flag when creating a buildpack", func() {
setupTestServer(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
}
}`},
}))
position := 999
created, apiErr := repo.Create("my-cool-buildpack", &position, nil, nil)
示例3:
_, apiErr := repo.FindByName("my-broker")
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).To(HaveOccurred())
Expect(apiErr.Error()).To(Equal("Service Broker my-broker not found"))
})
})
Describe("Create", func() {
It("creates the service broker with the given name, URL, username and password", func() {
expectedReqBody := `{"name":"foobroker","broker_url":"http://example.com","auth_username":"foouser","auth_password":"password"}`
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/service_brokers",
Matcher: testnet.RequestBodyMatcher(expectedReqBody),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createServiceBrokerRepo(req)
defer ts.Close()
apiErr := repo.Create("foobroker", "http://example.com", "foouser", "password")
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
})
})
Describe("Update", func() {
It("updates the service broker with the given guid", func() {
示例4:
`},
})
}
var matchResourceRequest = testnet.TestRequest{
Method: "PUT",
Path: "/v2/resource_match",
Matcher: testnet.RequestBodyMatcher(testnet.RemoveWhiteSpaceFromBody(`[
{
"sha1": "2474735f5163ba7612ef641f438f4b5bee00127b",
"size": 51
},
{
"sha1": "f097424ce1fa66c6cb9f5e8a18c317376ec12e05",
"size": 70
},
{
"sha1": "d9c3a51de5c89c11331d3b90b972789f1a14699a",
"size": 59
},
{
"sha1": "345f999aef9070fb9a608e65cf221b7038156b6d",
"size": 229
}
]`)),
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: matchedResources,
},
}
var matchResourceRequestImbalanced = testnet.TestRequest{
示例5:
createdApp, apiErr := repo.Create(params)
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
app := models.Application{}
app.Name = "my-cool-app"
app.Guid = "my-cool-app-guid"
Expect(createdApp).To(Equal(app))
})
It("omits fields that are not set", func() {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/apps",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-cool-app","instances":3,"memory":2048,"disk_quota":512,"space_guid":"some-space-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated, Body: createApplicationResponse},
})
ts, handler, repo := createAppRepo([]testnet.TestRequest{request})
defer ts.Close()
params := defaultAppParams()
params.BuildpackUrl = nil
params.StackGuid = nil
params.Command = nil
_, apiErr := repo.Create(params)
Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
})
示例6: createPasswordRepo
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testnet "github.com/cloudfoundry/cli/testhelpers/net"
. "github.com/cloudfoundry/cli/cf/api/password"
"github.com/cloudfoundry/cli/cf/trace/tracefakes"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("CloudControllerPasswordRepository", func() {
It("updates your password", func() {
req := apifakes.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 Repository) {
passwordServer, handler = testnet.NewServer([]testnet.TestRequest{req})
示例7:
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
gateway := cloudcontrollergateway.NewTestCloudControllerGateway(configRepo)
repo = NewCloudControllerServiceBindingRepository(configRepo, gateway)
})
AfterEach(func() {
testServer.Close()
})
Describe("Create", func() {
var requestMatcher testnet.RequestMatcher
Context("when the service binding can be created", func() {
BeforeEach(func() {
requestMatcher = testnet.RequestBodyMatcher(`{"app_guid":"my-app-guid","service_instance_guid":"my-service-instance-guid"}`)
})
JustBeforeEach(func() {
setupTestServer(apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/service_bindings",
Matcher: requestMatcher,
Response: testnet.TestResponse{Status: http.StatusCreated},
}))
})
It("creates the service binding", func() {
apiErr := repo.Create("my-service-instance-guid", "my-app-guid", nil)
Expect(testHandler).To(HaveAllRequestsCalled())
示例8:
testServer.Close()
})
setupTestServer := func(reqs ...testnet.TestRequest) {
testServer, testHandler = testnet.NewServer(reqs)
configRepo.SetAPIEndpoint(testServer.URL)
}
Describe(".Create", func() {
It("can create an app security group, given some attributes", func() {
req := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/security_groups",
// FIXME: this matcher depend on the order of the key/value pairs in the map
Matcher: testnet.RequestBodyMatcher(`{
"name": "mygroup",
"rules": [{"my-house": "my-rules"}]
}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
setupTestServer(req)
err := repo.Create(
"mygroup",
[]map[string]interface{}{{"my-house": "my-rules"}},
)
Expect(err).NotTo(HaveOccurred())
Expect(testHandler).To(HaveAllRequestsCalled())
})
})
示例9:
"github.com/cloudfoundry/cli/cf/net"
testapi "github.com/cloudfoundry/cli/testhelpers/api"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testnet "github.com/cloudfoundry/cli/testhelpers/net"
. "github.com/cloudfoundry/cli/cf/api"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("UserProvidedServiceRepository", func() {
It("creates a user provided service with a name and credentials", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/user_provided_service_instances",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-custom-service","credentials":{"host":"example.com","password":"secret","user":"me"},"space_guid":"my-space-guid","syslog_drain_url":""}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
})
ts, handler, repo := createUserProvidedServiceInstanceRepo(req)
defer ts.Close()
apiErr := repo.Create("my-custom-service", "", map[string]string{
"host": "example.com",
"user": "me",
"password": "secret",
})
Expect(handler).To(testnet.HaveAllRequestsCalled())
Expect(apiErr).NotTo(HaveOccurred())
})
示例10:
Expect(quotas[0].Name).To(Equal("my-remote-quota"))
Expect(quotas[0].MemoryLimit).To(Equal(uint64(1024)))
Expect(quotas[0].RoutesLimit).To(Equal(123))
Expect(quotas[0].ServicesLimit).To(Equal(321))
Expect(quotas[1].Guid).To(Equal("my-quota-guid2"))
Expect(quotas[2].Guid).To(Equal("my-quota-guid3"))
})
})
Describe("AssignQuotaToOrg", func() {
It("sets the quota for an organization", func() {
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},
})
setupTestServer(req)
err := repo.AssignQuotaToOrg("my-org-guid", "my-quota-guid")
Expect(testHandler).To(HaveAllRequestsCalled())
Expect(err).NotTo(HaveOccurred())
})
})
Describe("Create", func() {
It("creates a new quota with the given name", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
示例11:
})
It("returns a 'not found' response when the space doesn't exist in the given org", func() {
testSpacesDidNotFindByNameWithOrg("another-org-guid",
func(repo SpaceRepository, spaceName string) (models.Space, error) {
return repo.FindByNameInOrg(spaceName, "another-org-guid")
},
)
})
})
It("creates spaces without a space-quota", func() {
request := apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/spaces",
Matcher: testnet.RequestBodyMatcher(`{"name":"space-name","organization_guid":"my-org-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
"metadata": {
"guid": "space-guid"
},
"entity": {
"name": "space-name"
}
}`},
})
ts, handler, repo := createSpacesRepo(request)
defer ts.Close()
space, apiErr := repo.Create("space-name", "my-org-guid", "")
示例12:
}))
_, err := repo.FindByUsername("my-user")
Expect(uaaHandler).To(testnet.HaveAllRequestsCalled())
Expect(err).To(BeAssignableToTypeOf(&errors.ModelNotFoundError{}))
})
})
})
Describe("creating users", func() {
It("it creates users using the UAA /Users endpoint", func() {
setupCCServer(
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/users",
Matcher: testnet.RequestBodyMatcher(`{"guid":"my-user-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
}))
setupUAAServer(
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"}
}`),
示例13:
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())
示例14:
}}),
createProgressEndpoint("running"),
createProgressEndpoint("failed"),
}...)
Expect(apiErr).To(HaveOccurred())
})
Context("when there are no files to upload", func() {
It("makes a request without a zipfile", func() {
emptyDir := filepath.Join(fixturesDir, "empty-dir")
err := testUploadApp(emptyDir,
testnet.TestRequest{
Method: "PUT",
Path: "/v2/resource_match",
Matcher: testnet.RequestBodyMatcher("[]"),
Response: testnet.TestResponse{
Status: http.StatusOK,
Body: "[]",
},
},
testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/apps/my-cool-app-guid/bits",
Matcher: func(request *http.Request) {
err := request.ParseMultipartForm(maxMultipartResponseSizeInBytes)
Expect(err).NotTo(HaveOccurred())
defer request.MultipartForm.RemoveAll()
Expect(len(request.MultipartForm.Value)).To(Equal(1), "Should have 1 value")
valuePart, ok := request.MultipartForm.Value["resources"]
示例15:
})
It("returns a 'not found' response when the space doesn't exist in the given org", func() {
testSpacesDidNotFindByNameWithOrg("another-org-guid",
func(repo SpaceRepository, spaceName string) (models.Space, error) {
return repo.FindByNameInOrg(spaceName, "another-org-guid")
},
)
})
})
It("creates spaces", func() {
request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "POST",
Path: "/v2/spaces",
Matcher: testnet.RequestBodyMatcher(`{"name":"space-name","organization_guid":"my-org-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated, Body: `
{
"metadata": {
"guid": "space-guid"
},
"entity": {
"name": "space-name"
}
}`},
})
ts, handler, repo := createSpacesRepo(request)
defer ts.Close()
space, apiErr := repo.Create("space-name", "my-org-guid")