本文整理汇总了Golang中github.com/onsi/gomega/ghttp.VerifyJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang VerifyJSON函数的具体用法?Golang VerifyJSON怎么用?Golang VerifyJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VerifyJSON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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),
)
}
示例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),
)
}
示例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"}`),
),
示例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))
示例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"}
示例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",
示例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",
示例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),
示例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"}`),
),
)
示例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() {
示例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"}`),
),
)
示例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{
示例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),
示例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(
示例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)