本文整理汇总了Golang中github.com/onsi/gomega/ghttp.VerifyJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang VerifyJSON函数的具体用法?Golang VerifyJSON怎么用?Golang VerifyJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VerifyJSON函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deliverStoryHandler
func deliverStoryHandler(token string, projectId string, storyId int) http.HandlerFunc {
body := `{"current_state":"delivered"}`
return ghttp.CombineHandlers(
ghttp.VerifyRequest(
"PUT",
fmt.Sprintf("/services/v5/projects/%s/stories/%d", projectId, storyId),
), ghttp.VerifyHeaderKV("X-TrackerToken", token),
ghttp.VerifyJSON(body),
)
}
开发者ID:roxtar,项目名称:tracker-resource,代码行数:10,代码来源:out_test.go
示例2: deliverStoryCommentHandler
func deliverStoryCommentHandler(token string, projectId string, storyId int, comment string) http.HandlerFunc {
body := fmt.Sprintf(`{"text":"%s"}`, comment)
return ghttp.CombineHandlers(
ghttp.VerifyRequest(
"POST",
fmt.Sprintf("/services/v5/projects/%s/stories/%d/comments", projectId, storyId),
), ghttp.VerifyHeaderKV("X-TrackerToken", token),
ghttp.VerifyJSON(body),
)
}
开发者ID:roxtar,项目名称:tracker-resource,代码行数:10,代码来源:out_test.go
示例3:
gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
repo = NewCloudControllerServiceKeyRepository(configRepo, gateway)
})
AfterEach(func() {
ccServer.Close()
})
Describe("CreateServiceKey", func() {
It("tries to create the service key", func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v2/service_keys"),
ghttp.RespondWith(http.StatusCreated, nil),
ghttp.VerifyJSON(`{"service_instance_guid": "fake-instance-guid", "name": "fake-key-name"}`),
),
)
err := repo.CreateServiceKey("fake-instance-guid", "fake-key-name", nil)
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
Context("when the service key exists", func() {
BeforeEach(func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v2/service_keys"),
ghttp.RespondWith(http.StatusBadRequest, `{"code":360001,"description":"The service key name is taken: exist-service-key"}`),
),
开发者ID:rbramwell,项目名称:cli,代码行数:30,代码来源:service_keys_test.go
示例4:
completed,
assigneeID,
recurrenceType,
recurrenceCount,
"1968-01-02",
starred,
)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/tasks"),
ghttp.VerifyHeader(http.Header{
"X-Access-Token": []string{dummyAccessToken},
"X-Client-ID": []string{dummyClientID},
}),
ghttp.VerifyJSON(expectedBody),
),
)
client.CreateTask(
title,
listID,
assigneeID,
completed,
recurrenceType,
recurrenceCount,
dueDate,
starred,
)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
开发者ID:justincampbell,项目名称:wl,代码行数:31,代码来源:task_test.go
示例5:
})
It("returns an error", func() {
_, err := client.FindByUsername("[email protected]")
Expect(err).To(HaveOccurred())
})
})
})
Describe("Create", func() {
Context("when the user does not exist", func() {
BeforeEach(func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v2/users"),
ghttp.VerifyJSON(`{"guid":"my-user-guid"}`),
),
)
uaaServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/Users"),
ghttp.VerifyHeader(http.Header{
"accept": []string{"application/json"},
}),
ghttp.VerifyJSON(`{
"userName":"my-user",
"emails":[{"value":"my-user"}],
"password":"my-password",
"name":{
"givenName":"my-user",
"familyName":"my-user"}
开发者ID:brandontheis,项目名称:cli,代码行数:31,代码来源:users_test.go
示例6:
PersistentDisk: rackhdapi.PersistentDiskSettings{
DiskCID: "valid_disk_cid_2",
Location: "/dev/sdb",
IsAttached: false,
},
}
bodyBytes, err := json.Marshal(body)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/common/nodes"),
ghttp.RespondWith(http.StatusOK, expectedNodesData),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", "/api/common/nodes/55e79eb14e66816f6152fffb"),
ghttp.VerifyJSON(string(bodyBytes)),
),
)
err = DetachDisk(cpiConfig, extInput)
Expect(len(server.ReceivedRequests())).To(Equal(2))
Expect(err).NotTo(HaveOccurred())
})
})
})
})
Context("given a nonexistent disk CID", func() {
It("returns an error", func() {
jsonInput := []byte(`[
"valid_vm_cid_1",
开发者ID:heckj,项目名称:bosh-rackhd-cpi-release,代码行数:31,代码来源:detach_disk_test.go
示例7:
productFileID = 3456
expectedRequestBody = `{"product_file":{"id":3456}}`
)
Context("when the server responds with a 204 status code", func() {
It("returns without error", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", fmt.Sprintf(
"%s/products/%d/releases/%d/add_product_file",
apiPrefix,
productID,
releaseID,
)),
ghttp.VerifyJSON(expectedRequestBody),
ghttp.RespondWith(http.StatusNoContent, nil),
),
)
err := client.AddProductFile(productID, releaseID, productFileID)
Expect(err).NotTo(HaveOccurred())
})
})
Context("when the server responds with a non-201 status code", func() {
It("returns an error", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", fmt.Sprintf(
"%s/products/%d/releases/%d/add_product_file",
开发者ID:mdelillo,项目名称:pivnet-resource,代码行数:31,代码来源:product_files_test.go
示例8:
Describe("UpdateRelease", func() {
It("submits the updated values for a release", func() {
release := pivnet.Release{
ID: 42,
Eula: &pivnet.Eula{
Slug: "some-eula",
ID: 15,
},
}
patchURL := fmt.Sprintf("%s/products/%s/releases/%d", apiPrefix, "banana-slug", release.ID)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", patchURL),
ghttp.VerifyJSON(`{"release":{"id": 42, "eula":{"slug":"some-eula","id":15}}}`),
ghttp.RespondWith(http.StatusOK, nil),
),
)
Expect(client.UpdateRelease("banana-slug", release)).To(Succeed())
})
Context("when the server responds with a non-200 status code", func() {
It("returns the error", func() {
release := pivnet.Release{ID: 111}
patchURL := fmt.Sprintf("%s/products/%s/releases/%d", apiPrefix, "banana-slug", release.ID)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", patchURL),
开发者ID:mdelillo,项目名称:pivnet-resource,代码行数:31,代码来源:releases_test.go
示例9:
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
ghttp.RespondWith(http.StatusCreated, nil),
),
)
err := routeServiceBindingRepo.Bind(serviceInstanceGuid, routeGuid, true, "")
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
It("creates the service binding with the provided body", func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
ghttp.RespondWith(http.StatusCreated, nil),
ghttp.VerifyJSON(`{"some":"json"}`),
),
)
err := routeServiceBindingRepo.Bind(serviceInstanceGuid, routeGuid, true, `{"some":"json"}`)
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
Context("when an API error occurs", func() {
BeforeEach(func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/service_instances/%s/routes/%s", serviceInstanceGuid, routeGuid)),
ghttp.RespondWith(http.StatusBadRequest, `{"code":61003,"description":"Route does not exist"}`),
),
)
开发者ID:sunatthegilddotcom,项目名称:cli,代码行数:31,代码来源:route_service_binding_repository_test.go
示例10:
})
AfterEach(func() {
if ccServer != nil {
ccServer.Close()
}
})
Context("when no host, path, or port are given", func() {
BeforeEach(func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v2/routes", "inline-relations-depth=1&async=true"),
ghttp.VerifyJSON(`
{
"domain_guid":"my-domain-guid",
"space_guid":"my-space-guid"
}
`),
ghttp.VerifyHeader(http.Header{
"accept": []string{"application/json"},
}),
),
)
})
It("tries to create a route", func() {
repo.CreateInSpace("", "", "my-domain-guid", "my-space-guid", 0, false)
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
Context("when creating the route succeeds", func() {
开发者ID:fujitsu-cf,项目名称:cli,代码行数:32,代码来源:routes_test.go
示例11:
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
ghttp.RespondWith(http.StatusCreated, nil),
),
)
err := routeServiceBindingRepo.Bind(serviceInstanceGUID, routeGUID, true, "")
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
It("creates the service binding with the provided body wrapped in parameters", func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/user_provided_service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
ghttp.RespondWith(http.StatusCreated, nil),
ghttp.VerifyJSON(`{"parameters":{"some":"json"}}`),
),
)
err := routeServiceBindingRepo.Bind(serviceInstanceGUID, routeGUID, true, `{"some":"json"}`)
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
Context("when an API error occurs", func() {
BeforeEach(func() {
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", fmt.Sprintf("/v2/service_instances/%s/routes/%s", serviceInstanceGUID, routeGUID)),
ghttp.RespondWith(http.StatusBadRequest, `{"code":61003,"description":"Route does not exist"}`),
),
)
开发者ID:yingkitw,项目名称:cli,代码行数:31,代码来源:route_service_binding_repository_test.go
示例12:
// Perform the test by running main() with the command line args set
It(strings.Join(testCase.CmdArgs, " "), func() {
//server := httptest.NewTLSServer(http.HandlerFunc(handler))
server := ghttp.NewServer()
defer server.Close()
// construct list of verifiers
url := regexp.MustCompile(`https?://[^/]+(/[^?]+)\??(.*)`).
FindStringSubmatch(testCase.RR.URI)
//fmt.Fprintf(os.Stderr, "URL: %#v\n", url)
handlers := []http.HandlerFunc{
ghttp.VerifyRequest(testCase.RR.Verb, url[1], url[2]),
}
if len(testCase.RR.ReqBody) > 0 {
handlers = append(handlers,
ghttp.VerifyJSON(testCase.RR.ReqBody))
}
for k := range testCase.RR.ReqHeader {
handlers = append(handlers,
ghttp.VerifyHeaderKV(k, testCase.RR.ReqHeader.Get(k)))
}
respHeader := make(http.Header)
for k, v := range testCase.RR.RespHeader {
respHeader[k] = v
}
handlers = append(handlers,
ghttp.RespondWith(testCase.RR.Status, testCase.RR.RespBody,
respHeader))
server.AppendHandlers(ghttp.CombineHandlers(handlers...))
os.Args = append([]string{
开发者ID:lopaka,项目名称:rsc,代码行数:31,代码来源:recording_test.go
示例13:
)
BeforeEach(func() {
productSlug = "banana-slug"
releaseID = 42
EULAAcceptanceURL = fmt.Sprintf(apiPrefix+"/products/%s/releases/%d/eula_acceptance", productSlug, releaseID)
})
It("accepts the EULA for a given release and product ID", func() {
response := fmt.Sprintf(`{"accepted_at": "2016-01-11","_links":{}}`)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", EULAAcceptanceURL),
ghttp.VerifyHeaderKV("Authorization", fmt.Sprintf("Token %s", token)),
ghttp.VerifyJSON(`{}`),
ghttp.RespondWith(http.StatusOK, response),
),
)
Expect(client.AcceptEULA(productSlug, releaseID)).To(Succeed())
})
Context("when any other non-200 status code comes back", func() {
It("returns an error", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", EULAAcceptanceURL),
ghttp.VerifyHeaderKV("Authorization", fmt.Sprintf("Token %s", token)),
ghttp.VerifyJSON(`{}`),
ghttp.RespondWith(http.StatusTeapot, nil),
开发者ID:mdelillo,项目名称:pivnet-resource,代码行数:31,代码来源:pivnet_client_test.go
示例14:
OccurredBefore: 1433091819000,
OccurredAfter: 1000000000000,
SinceVersion: 1,
}
activities, err := client.InProject(99).StoryActivity(560, query)
Ω(activities).Should(HaveLen(4))
Ω(err).ToNot(HaveOccurred())
})
})
Describe("delivering a story", func() {
It("HTTP PUTs it in its place", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/services/v5/projects/99/stories/15225523"),
ghttp.VerifyJSON(`{"current_state":"delivered"}`),
verifyTrackerToken(),
ghttp.RespondWith(http.StatusOK, ""),
),
)
client := tracker.NewClient("api-token")
err := client.InProject(99).DeliverStory(15225523)
Ω(err).ShouldNot(HaveOccurred())
})
It("HTTP PUTs it in its place with a comment", func() {
comment := "some delivery comment"
server.AppendHandlers(
开发者ID:robdimsdale,项目名称:go-tracker,代码行数:31,代码来源:client_test.go
示例15:
var apiKey string = "S0m3Ap1K3y"
var accountId string = "123abc"
auth := &main.Auth{
Email: email,
Password: password,
}
BeforeEach(func() {
server = ghttp.NewServer()
main.BaseUrl = server.URL()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/auth"),
ghttp.VerifyHeader(http.Header{"User-Agent": []string{"imgix-cli v0.1.0"}}),
ghttp.VerifyJSON(fmt.Sprintf(`{ "password": "%s", "email": "%s" }`, password, email)),
ghttp.RespondWith(http.StatusOK, fmt.Sprintf(`{
"account_id": "%s",
"api_key": "%s",
"email": "%s"
}`, accountId, apiKey, email)),
),
)
})
AfterEach(func() {
server.Close()
})
It("sends off the request", func() {
main.PostAuth(auth)
开发者ID:imgix,项目名称:imgix-cli,代码行数:31,代码来源:auth_test.go
示例16:
Describe("creating a new list", func() {
var title string
BeforeEach(func() {
title = "a list"
})
It("performs POST requests with correct headers to /lists", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/lists"),
ghttp.VerifyHeader(http.Header{
"X-Access-Token": []string{dummyAccessToken},
"X-Client-ID": []string{dummyClientID},
}),
ghttp.VerifyJSON(`{"title":"a list"}`),
),
)
client.CreateList(title)
Expect(server.ReceivedRequests()).Should(HaveLen(1))
})
Context("when the request is valid", func() {
It("returns successfully", func() {
expectedList := wl.List{ID: 2345}
// Marshal and unmarshal to ensure exact object is returned
// - this avoids odd behavior with the time fields
expectedBody, err := json.Marshal(expectedList)
开发者ID:justincampbell,项目名称:wl,代码行数:31,代码来源:list_test.go
示例17:
"github.com/concourse/go-concourse/concourse"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
var _ = Describe("CheckResource", func() {
Context("when ATC request succeeds", func() {
BeforeEach(func() {
expectedURL := "/api/v1/teams/some-team/pipelines/mypipeline/resources/myresource/check"
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", expectedURL),
ghttp.VerifyJSON(`{"from":{"ref":"fake-ref"}}`),
ghttp.RespondWithJSONEncoded(http.StatusOK, ""),
),
)
})
It("sends check resource request to ATC", func() {
found, err := team.CheckResource("mypipeline", "myresource", atc.Version{"ref": "fake-ref"})
Expect(err).NotTo(HaveOccurred())
Expect(found).To(BeTrue())
Expect(atcServer.ReceivedRequests()).To(HaveLen(1))
})
})
Context("when pipeline or resource does not exist", func() {
开发者ID:concourse,项目名称:go-concourse,代码行数:31,代码来源:check_resource_test.go
示例18:
),
)
})
Context("when there is a VM left on the node", func() {
It("deletes the disk", func() {
jsonInput := []byte(`[
"valid_disk_cid_3"
]`)
err := json.Unmarshal(jsonInput, &extInput)
Expect(err).NotTo(HaveOccurred())
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PATCH", "/api/common/nodes/55e79e9f4e66816f6152fff5"),
ghttp.VerifyJSON(string(expectedDeleteDiskBodyBytes)),
),
)
err = DeleteDisk(cpiConfig, extInput)
Expect(len(server.ReceivedRequests())).To(Equal(2))
Expect(err).NotTo(HaveOccurred())
})
})
Context("when there is no VM left on the node", func() {
It("deletes the disk and sets the status to available", func() {
jsonInput := []byte(`[
"valid_disk_cid_1"
]`)
err := json.Unmarshal(jsonInput, &extInput)
开发者ID:cloudfoundry-incubator,项目名称:bosh-rackhd-cpi-release,代码行数:31,代码来源:delete_disk_test.go
示例19:
SpaceGUID: &spaceGUID,
StackGUID: &stackGUID,
Command: &command,
Memory: &memory,
DiskQuota: &diskQuota,
InstanceCount: &instanceCount,
}
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v2/apps"),
ghttp.VerifyJSON(`{
"name":"my-cool-app",
"instances":3,
"buildpack":"buildpack-url",
"memory":2048,
"disk_quota": 512,
"space_guid":"some-space-guid",
"stack_guid":"some-stack-guid",
"command":"some-command"
}`),
),
)
})
AfterEach(func() {
ccServer.Close()
})
It("tries to create the app", func() {
repo.Create(appParams)
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
开发者ID:yingkitw,项目名称:cli,代码行数:32,代码来源:applications_test.go
示例20:
server = ghttp.NewServer()
main.BaseUrl = server.URL()
editableSource = &main.EditableSource{
Name: sourceName,
}
firstResponse := `{}`
secondResponse := `{}`
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/sources/"+sourceId, ""),
ghttp.RespondWithJSONEncoded(http.StatusOK, firstResponse),
correctUserAgent,
correctAuthHeader,
ghttp.VerifyJSON(fmt.Sprintf(`{ "name": "%s" }`, sourceName)),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/sources/"+sourceId+"/config", ""),
ghttp.RespondWithJSONEncoded(http.StatusOK, secondResponse),
correctUserAgent,
correctAuthHeader,
ghttp.VerifyJSON(fmt.Sprintf(`{
"cache_ttl_browser": 0,
"cache_ttl_error": 0,
"cache_ttl_fetch": 0,
"cache_ttl_render": 0,
"crossdomain_cors_enabled": false,
"crossdomain_cors_hosts": "",
"crossdomain_xml_enabled": false,
"crossdomain_xml_hosts": "",
开发者ID:imgix,项目名称:imgix-cli,代码行数:31,代码来源:sources_actions_test.go
注:本文中的github.com/onsi/gomega/ghttp.VerifyJSON函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论