本文整理汇总了Golang中github.com/onsi/gomega/ghttp.Server.ReceivedRequests方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.ReceivedRequests方法的具体用法?Golang Server.ReceivedRequests怎么用?Golang Server.ReceivedRequests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/onsi/gomega/ghttp.Server
的用法示例。
在下文中一共展示了Server.ReceivedRequests方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
})
Describe("listing", func() {
BeforeEach(func() {
do.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/actions"),
ghttp.RespondWith(http.StatusOK, doGetActions),
),
)
})
It("lists all actions", func() {
resp, err := client.Get("/actions")
Expect(err).NotTo(HaveOccurred())
Ω(do.ReceivedRequests()).Should(HaveLen(1))
var actions map[string]interface{}
err = json.Unmarshal([]byte(doGetActions), &actions)
Expect(err).NotTo(HaveOccurred())
expected, err := json.Marshal(actions["actions"])
Expect(err).NotTo(HaveOccurred())
Ω(resp.Body).Should(MatchJSON(expected))
})
})
Describe("listing empty", func() {
BeforeEach(func() {
do.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/actions"),
ghttp.RespondWith(http.StatusOK, doGetEmpty),
示例2:
err := bbsClient.StartActualLRP(&lrpKey, &instanceKey, &netInfo)
Expect(err).NotTo(HaveOccurred())
actualLRPGroup, err := bbsClient.ActualLRPGroupByProcessGuidAndIndex(lrpKey.ProcessGuid, int(lrpKey.Index))
Expect(err).NotTo(HaveOccurred())
runningLRP = actualLRPGroup.GetInstance()
})
It("should destroy the container", func() {
Eventually(getActualLRPGroups).Should(HaveLen(1))
err := bbsClient.RetireActualLRP(&runningLRP.ActualLRPKey)
Expect(err).NotTo(HaveOccurred())
findDestroyRequest := func() bool {
for _, req := range fakeGarden.ReceivedRequests() {
if req.URL.Path == expectedDestroyRoute {
return true
}
}
return false
}
Eventually(findDestroyRequest).Should(BeTrue())
})
})
Describe("cancelling tasks", func() {
const taskGuid = "some-task-guid"
const expectedDeleteRoute = "/containers/" + taskGuid
示例3:
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"}`),
),
)
})
It("returns a ModelAlreadyExistsError", func() {
err := repo.CreateServiceKey("fake-instance-guid", "exist-service-key", nil)
Expect(err).To(BeAssignableToTypeOf(&errors.ModelAlreadyExistsError{}))
示例4:
Expect(err).NotTo(HaveOccurred())
Expect(proxyHostKey.PublicKey().Marshal()).To(Equal(handshakeHostKey.Marshal()))
})
Describe("attempting authentication without a realm", func() {
BeforeEach(func() {
clientConfig = &ssh.ClientConfig{
User: processGuid + "/99",
Auth: []ssh.AuthMethod{ssh.Password(diegoCredentials)},
}
})
It("fails the authentication", func() {
_, err := ssh.Dial("tcp", address, clientConfig)
Expect(err).To(MatchError(ContainSubstring("ssh: handshake failed")))
Expect(fakeBBS.ReceivedRequests()).To(HaveLen(0))
})
})
Describe("attempting authentication with an unknown realm", func() {
BeforeEach(func() {
clientConfig = &ssh.ClientConfig{
User: "goo:" + processGuid + "/99",
Auth: []ssh.AuthMethod{ssh.Password(diegoCredentials)},
}
})
It("fails the authentication", func() {
_, err := ssh.Dial("tcp", address, clientConfig)
Expect(err).To(MatchError(ContainSubstring("ssh: handshake failed")))
Expect(fakeBBS.ReceivedRequests()).To(HaveLen(0))
示例5:
{
"route": "zak.com",
"port": 3,
"ip": "4",
"ttl": 0,
"log_guid": "",
},
}),
ghttp.RespondWithJSONEncoded(http.StatusOK, nil),
),
)
session := routeRegistrar(command...)
Eventually(session, "2s").Should(Exit(0))
Expect(server.ReceivedRequests()).To(HaveLen(1))
})
It("registers multiple routes to the routing api", func() {
routes := `[{"route":"zak.com","port":0,"ip": "","ttl":5,"log_guid":"yo"},{"route":"jak.com","port":8,"ip":"11","ttl":0}]`
command := buildCommand("register", flags, []string{routes})
server.SetHandler(0,
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v1/routes"),
ghttp.VerifyJSONRepresenting([]map[string]interface{}{
{
"route": "zak.com",
"port": 0,
"ip": "",
"ttl": 5,
"log_guid": "yo",
示例6:
err := json.Unmarshal(jsonInput, &extInput)
Expect(err).ToNot(HaveOccurred())
expectedNodes := helpers.LoadNodes("../spec_assets/dummy_attached_disk_response.json")
expectedNodesData, err := json.Marshal(expectedNodes)
Expect(err).ToNot(HaveOccurred())
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/common/nodes"),
ghttp.RespondWith(http.StatusOK, expectedNodesData),
),
)
err = DetachDisk(cpiConfig, extInput)
Expect(err).To(MatchError("Disk: valid_disk_cid_1 is detached\n"))
Expect(len(server.ReceivedRequests())).To(Equal(1))
})
})
Context("given a disk that is attached", func() {
Context("when given a vm cid that the disk does not belong to", func() {
It("returns an error", func() {
jsonInput := []byte(`[
"invalid_vm_cid_2",
"valid_disk_cid_2"
]`)
var extInput bosh.MethodArguments
err := json.Unmarshal(jsonInput, &extInput)
Expect(err).ToNot(HaveOccurred())
expectedNodes := helpers.LoadNodes("../spec_assets/dummy_attached_disk_response.json")
示例7:
ghttp.VerifyRequest("GET", "/v2/stacks", "q=name%3Alinux"),
ghttp.RespondWith(http.StatusOK, `{
"resources": [
{
"metadata": { "guid": "custom-linux-guid" },
"entity": { "name": "custom-linux" }
}
]
}`),
),
)
})
It("tries to find the stack", func() {
repo.FindByName("linux")
Expect(testServer.ReceivedRequests()).To(HaveLen(1))
})
It("returns the stack", func() {
stack, err := repo.FindByName("linux")
Expect(err).NotTo(HaveOccurred())
Expect(stack).To(Equal(models.Stack{
Name: "custom-linux",
GUID: "custom-linux-guid",
}))
})
})
Context("when the stack cannot be found", func() {
BeforeEach(func() {
testServer.AppendHandlers(
示例8:
})
})
Context("as any other node", func() {
BeforeEach(func() {
node = newNode(func() {
ranThing("A")
}, func() {
ranThing("B")
})
outcome = node.Run(2, 3, server.URL())
})
It("should run A, and not run B", func() {
Ω(thingsThatRan()).Should(Equal([]string{"A"}))
})
It("should not talk to the server", func() {
Ω(server.ReceivedRequests()).Should(BeEmpty())
})
It("should report success", func() {
Ω(outcome).Should(BeTrue())
Ω(node.Passed()).Should(BeTrue())
Ω(node.Summary().State).Should(Equal(types.SpecStatePassed))
})
})
})
})
示例9:
registryHost = parts.Host
dockerRegistryServer.RouteToHandler("GET", "/v1/_ping", ghttp.VerifyRequest("GET", "/v1/_ping"))
dockerRegistryServer.RouteToHandler("GET", "/v2/", ghttp.VerifyRequest("GET", "/v2/"))
})
Context("when connecting to a secure registry", func() {
It("creates a registry session for the given repo", func() {
session, err := sessionFactory.MakeSession(registryHost+"/lattice-mappppppppppppappapapa", false)
Expect(err).NotTo(HaveOccurred())
registrySession, ok := session.(*registry.Session)
Expect(ok).To(BeTrue())
Expect(*registrySession.GetAuthConfig(true)).To(Equal(registry.AuthConfig{}))
Expect(dockerRegistryServer.ReceivedRequests()).To(HaveLen(2))
})
})
Context("when connecting to an insecure registry", func() {
It("creates a registry session for the given repo", func() {
session, err := sessionFactory.MakeSession(registryHost+"/lattice-mappppppppppppappapapa", true)
Expect(err).NotTo(HaveOccurred())
registrySession, ok := session.(*registry.Session)
Expect(ok).To(BeTrue())
Expect(*registrySession.GetAuthConfig(true)).To(Equal(registry.AuthConfig{}))
Expect(dockerRegistryServer.ReceivedRequests()).To(HaveLen(2))
})
})
示例10:
addBackendRoute("/foo", "backend", "prefix")
reloadRoutes()
})
AfterEach(func() {
recorder.Close()
})
It("should pass through most http headers to the backend", func() {
resp := routerRequestWithHeaders("/foo", map[string]string{
"Foo": "bar",
"User-Agent": "Router test suite 2.7182",
})
Expect(resp.StatusCode).To(Equal(200))
Expect(recorder.ReceivedRequests()).To(HaveLen(1))
beReq := recorder.ReceivedRequests()[0]
Expect(beReq.Header.Get("Foo")).To(Equal("bar"))
Expect(beReq.Header.Get("User-Agent")).To(Equal("Router test suite 2.7182"))
})
It("should set the Host header to the backend hostname", func() {
resp := routerRequestWithHeaders("/foo", map[string]string{
"Host": "www.example.com",
})
Expect(resp.StatusCode).To(Equal(200))
Expect(recorder.ReceivedRequests()).To(HaveLen(1))
beReq := recorder.ReceivedRequests()[0]
Expect(beReq.Host).To(Equal(recorderURL.Host))
})
示例11:
AfterEach(func() {
ccServer.Close()
})
Context("when given a non-zero positive limit", func() {
It("should return no more than the limit number of organizations", func() {
orgs, err := repo.ListOrgs(2)
Expect(err).NotTo(HaveOccurred())
Expect(len(orgs)).To(Equal(2))
})
It("should not make more requests than necessary to retrieve the requested number of orgs", func() {
_, err := repo.ListOrgs(2)
Expect(err).NotTo(HaveOccurred())
Expect(ccServer.ReceivedRequests()).Should(HaveLen(1))
})
})
Context("when given a zero limit", func() {
It("should return all organizations", func() {
orgs, err := repo.ListOrgs(0)
Expect(err).NotTo(HaveOccurred())
Expect(len(orgs)).To(Equal(3))
})
})
})
Describe(".GetManyOrgsByGuid", func() {
It("requests each org", func() {
firstOrgRequest := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
示例12:
})
})
})
Context("and the engine returns no build", func() {
BeforeEach(func() {
fakeEngine.LookupBuildReturns(nil, errors.New("oh no!"))
})
It("returns 500", func() {
Ω(response.StatusCode).Should(Equal(http.StatusInternalServerError))
})
})
})
Context("when not authenticated", func() {
BeforeEach(func() {
authValidator.IsAuthenticatedReturns(false)
})
It("returns 401", func() {
Ω(response.StatusCode).Should(Equal(http.StatusUnauthorized))
})
It("does not abort the build", func() {
Ω(abortTarget.ReceivedRequests()).Should(BeEmpty())
})
})
})
})
示例13:
process = ginkgomon.Invoke(runner)
})
AfterEach(func() {
ginkgomon.Interrupt(process)
testServer.Close()
testS3Server.Close()
close(bodyChan)
err := os.Remove(comparisonFilePath)
Expect(err).ToNot(HaveOccurred())
})
It("ramps up throughput over multiple tests", func() {
Eventually(process.Wait(), "5s").Should(Receive())
Expect(runner.ExitCode()).To(Equal(0))
Expect(testServer.ReceivedRequests()).To(HaveLen(24))
})
Context("when cpu monitor server is configured", func() {
var (
cpumonitorServer *ghttp.Server
)
BeforeEach(func() {
cpumonitorServer = ghttp.NewServer()
header := make(http.Header)
header.Add("Content-Type", "application/json")
cpumonitorServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/start"),
示例14:
ghttp.VerifyJSON(requestJSON("disaster")),
ghttp.RespondWith(200, ""),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api-token"),
ghttp.VerifyJSON(requestJSON("disaster")),
ghttp.RespondWith(200, ""),
),
)
})
It("tries the next collector", func() {
err := errors.New("disaster")
client.Notify("holler.example.failed", err, data)
Expect(otherCollector.ReceivedRequests()).To(HaveLen(1))
})
})
Context("when an unexpected error occurs", func() {
Context("when it is a transport error", func() {
BeforeEach(func() {
collector.Close()
collector = nil
otherCollector.Close()
otherCollector = nil
})
It("logs the error", func() {
err := errors.New("disaster")
示例15:
Context("endpoint returns 404 mimicing CF app with no instances", func() {
BeforeEach(func() {
server.RouteToHandler("GET", "/",
ghttp.CombineHandlers(
ghttp.RespondWith(http.StatusNotFound, ""),
),
)
})
It("reports the requests as not successful", func() {
attacker, resultChannel := loadTest(server.URL(), availabilityTestRate)
defer attacker.Stop()
Eventually(func() int {
return len(server.ReceivedRequests())
}).Should(BeNumerically(">", 1))
attacker.Stop()
for result := range resultChannel {
metrics.Add(result)
}
metrics.Close()
Expect(metrics.Success * 100).To(BeNumerically("==", 0))
})
})
})
Context("when runs (until the deployment is finished or error rate > 50%)", func() {
var attacker *vegeta.Attacker
var resultChannel <-chan *vegeta.Result