本文整理汇总了Golang中github.com/onsi/gomega/ghttp.Server.AppendHandlers方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.AppendHandlers方法的具体用法?Golang Server.AppendHandlers怎么用?Golang Server.AppendHandlers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/onsi/gomega/ghttp.Server
的用法示例。
在下文中一共展示了Server.AppendHandlers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewTestServer
func NewTestServer(server *ghttp.Server) *ghttp.Server {
sampleSuccessTokenStringFormat := `{"access_token":"%s","token_type":"bearer","refresh_token":"%s","expires_in":599,"scope":"password.write cloud_controller.write openid cloud_controller.read","jti":"%s"}`
loginTokenResponse := fmt.Sprintf(sampleSuccessTokenStringFormat, "access-token", "refresh-token", "jti")
aiBasicResponse, _ := ioutil.ReadFile("fixtures/ai_basic_response.json")
aiInfoHandler := ghttp.RespondWith(http.StatusOK, aiBasicResponse)
aiDeleteHandler := ghttp.RespondWith(http.StatusNoContent, "")
aiInfoPath, _ := regexp.Compile("/v2/apps/.*/instances")
aiDeletePath, _ := regexp.Compile("/v2/apps/.*/instances/.*")
server.RouteToHandler("GET", aiInfoPath, aiInfoHandler)
server.RouteToHandler("DELETE", aiDeletePath, aiDeleteHandler)
server.RouteToHandler("POST", "/oauth/token", ghttp.RespondWith(http.StatusOK, "{}"))
server.AppendHandlers(
ghttp.RespondWith(http.StatusOK, loginTokenResponse),
)
return server
}
示例2: setupSuccessfulFetch
func setupSuccessfulFetch(server *ghttp.Server) {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-3/json"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("X-Docker-Size", "123")
w.Write([]byte(`{"id":"layer-3","parent":"parent-3","Config":{"env": ["env2=env2Value", "malformedenvvar"]}}`))
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-3/layer"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(`layer-3-data`))
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-2/json"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("X-Docker-Size", "456")
w.Write([]byte(`{"id":"layer-2","parent":"parent-2","Config":{"volumes": { "/tmp": {}, "/another": {} }, "env": ["env1=env1Value", "env2=env2NewValue"]}}`))
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-2/layer"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(`layer-2-data`))
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-1/json"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("X-Docker-Size", "789")
w.Write([]byte(`{"id":"layer-1","parent":"parent-1"}`))
}),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v1/images/layer-1/layer"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(`layer-1-data`))
}),
),
)
}
示例3: setupSuccessfulV2Fetch
func setupSuccessfulV2Fetch(server *ghttp.Server, layer1Cached bool) {
layer1Data := "banana-1-flan"
layer1Dgst, _ := digest.FromBytes([]byte(layer1Data))
layer2Data := "banana-2-flan"
layer2Dgst, _ := digest.FromBytes([]byte(layer2Data))
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/some-repo/manifests/some-tag"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(fmt.Sprintf(`
{
"name":"some-repo",
"tag":"some-tag",
"fsLayers":[
{
"blobSum":"%s"
},
{
"blobSum":"%s"
}
],
"history":[
{
"v1Compatibility": "{\"id\":\"banana-pie-2\", \"parent\":\"banana-pie-1\"}"
},
{
"v1Compatibility": "{\"id\":\"banana-pie-1\"}"
}
]
}
`, layer2Dgst.String(), layer1Dgst.String())))
}),
),
)
if !layer1Cached {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", fmt.Sprintf("/v2/some-repo/blobs/%s", layer1Dgst)),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(layer1Data))
}),
),
)
}
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", fmt.Sprintf("/v2/some-repo/blobs/%s", layer2Dgst)),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(layer2Data))
}),
),
)
}
示例4:
"description":"",
"authorization_endpoint":"https://login.APISERVER",
"token_endpoint":"https://uaa.APISERVER",
"min_cli_version":null,
"min_recommended_cli_version":null,
"api_version":"2.59.0",
"app_ssh_endpoint":"ssh.APISERVER",
"app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a",
"app_ssh_oauth_client":"ssh-proxy",
"logging_endpoint":"wss://loggregator.APISERVER",
"doppler_logging_endpoint":"wss://doppler.APISERVER"
}`
response = strings.Replace(response, "APISERVER", serverAPIURL, -1)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/info"),
ghttp.RespondWith(http.StatusOK, response),
),
)
})
AfterEach(func() {
server.Close()
})
It("falls back to http and gives a warning", func() {
command := exec.Command("cf", "api", server.URL(), "--skip-ssl-validation")
session, err := Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session.Out).Should(Say("Setting api endpoint to %s...", server.URL()))
Eventually(session.Out).Should(Say("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended"))
示例5:
Nice: rlimits.Nice,
Nofile: rlimits.Nofile,
Nproc: rlimits.Nproc,
Rss: rlimits.Rss,
Rtprio: rlimits.Rtprio,
Sigpending: rlimits.Sigpending,
Stack: rlimits.Stack,
}
})
Describe("Ping", func() {
Context("when the response is successful", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/ping"),
ghttp.RespondWith(200, "{}"),
),
)
})
It("should ping the server", func() {
err := connection.Ping()
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("when the request fails", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/ping"),
示例6:
BaseURL: server.URL(),
}
route = "/some/route"
})
AfterEach(func() {
server.Close()
})
Describe("Get", func() {
BeforeEach(func() {
serverHandler = ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", route),
ghttp.RespondWith(http.StatusOK, `{ "SomeResponseField": "some value" }`),
)
server.AppendHandlers(serverHandler)
})
It("should make a get request to the given route", func() {
err := c.Get(route, &responseStruct)
Expect(err).NotTo(HaveOccurred())
Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(responseStruct.SomeResponseField).To(Equal("some value"))
})
Context("when the request cannot be created", func() {
It("should return an error", func() {
err := c.Get("%%%", &responseStruct)
Expect(err).To(MatchError(ContainSubstring("parse")))
})
})
示例7:
})
Context("when starting", func() {
var deleteChan chan struct{}
BeforeEach(func() {
fakeGarden.RouteToHandler("GET", "/containers",
ghttp.RespondWithJSONEncoded(http.StatusOK, map[string][]string{"handles": []string{"cnr1", "cnr2"}}),
)
deleteChan = make(chan struct{}, 2)
fakeGarden.AppendHandlers(
ghttp.CombineHandlers(ghttp.VerifyRequest("DELETE", "/containers/cnr1"),
func(http.ResponseWriter, *http.Request) {
deleteChan <- struct{}{}
},
ghttp.RespondWithJSONEncoded(http.StatusOK, &struct{}{})),
ghttp.CombineHandlers(ghttp.VerifyRequest("DELETE", "/containers/cnr2"),
func(http.ResponseWriter, *http.Request) {
deleteChan <- struct{}{}
},
ghttp.RespondWithJSONEncoded(http.StatusOK, &struct{}{})),
)
})
It("destroys any existing containers", func() {
Eventually(deleteChan).Should(Receive())
Eventually(deleteChan).Should(Receive())
})
})
Describe("maintaining presence", func() {
var cellPresence *models.CellPresence
示例8:
Context("when the pipeline name is specified", func() {
var (
path string
err error
)
BeforeEach(func() {
path, err = atc.Routes.CreatePathForRoute(atc.PausePipeline, rata.Params{"pipeline_name": "awesome-pipeline"})
Expect(err).NotTo(HaveOccurred())
})
Context("when the pipeline exists", func() {
BeforeEach(func() {
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", path),
ghttp.RespondWith(http.StatusOK, nil),
),
)
})
It("pauses the pipeline", func() {
flyCmd := exec.Command(flyPath, "-t", atcServer.URL(), "pause-pipeline", "-p", "awesome-pipeline")
sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gbytes.Say(`paused 'awesome-pipeline'`))
<-sess.Exited
Expect(sess.ExitCode()).To(Equal(0))
Expect(atcServer.ReceivedRequests()).To(HaveLen(1))
示例9:
BeforeEach(func() {
uaaServer = ghttp.NewServer()
config = testconfig.NewRepository()
config.SetAuthenticationEndpoint(uaaServer.URL())
config.SetSSHOAuthClient("ssh-oauth-client")
gateway = net.NewUAAGateway(config, &testterm.FakeUI{})
authRepo = NewUAAAuthenticationRepository(gateway, config)
uaaServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyHeader(http.Header{"authorization": []string{"auth-token"}}),
ghttp.VerifyRequest("GET", "/oauth/authorize",
"response_type=code&grant_type=authorization_code&client_id=ssh-oauth-client",
),
ghttp.RespondWith(http.StatusFound, ``, http.Header{
"Location": []string{"https://www.cloudfoundry.example.com?code=F45jH"},
}),
),
)
})
AfterEach(func() {
uaaServer.Close()
})
It("requests the one time code", func() {
_, err := authRepo.Authorize("auth-token")
Expect(err).NotTo(HaveOccurred())
Expect(uaaServer.ReceivedRequests()).To(HaveLen(1))
示例10:
})
})
Describe("delete", func() {
var (
httpStatusCode int
fakeServer *ghttp.Server
fakeServerURL, sanitizedURL string
)
BeforeEach(func() {
httpStatusCode = http.StatusNoContent
fakeServer = ghttp.NewServer()
fakeServer.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/blobs/path"),
ghttp.RespondWithPtr(&httpStatusCode, nil),
ghttp.VerifyBasicAuth("user", "pass"),
))
fakeServerURL = fmt.Sprintf("http://%s:%[email protected]%s%s", "user", "pass", fakeServer.Addr(), "/blobs/path")
sanitizedURL = fmt.Sprintf("http://%s%s", fakeServer.Addr(), "/blobs/path")
})
AfterEach(func() {
fakeServer.Close()
})
It("does a DELETE to the DAV server to delete the file", func() {
command := exec.Command(davtoolPath, "delete", fakeServerURL)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
示例11:
const cellAddr = "cell.example.com"
var stopErr error
var actualLRP = models.ActualLRP{
ActualLRPKey: models.NewActualLRPKey("some-process-guid", 2, "test-domain"),
ActualLRPInstanceKey: models.NewActualLRPInstanceKey("some-instance-guid", "some-cell-id"),
}
JustBeforeEach(func() {
stopErr = client.StopLRPInstance(actualLRP.ActualLRPKey, actualLRP.ActualLRPInstanceKey)
})
Context("when the request is successful", func() {
BeforeEach(func() {
fakeServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v1/lrps/some-process-guid/instances/some-instance-guid/stop"),
ghttp.RespondWith(http.StatusAccepted, ""),
),
)
})
It("makes the request and does not return an error", func() {
Expect(stopErr).NotTo(HaveOccurred())
Expect(fakeServer.ReceivedRequests()).To(HaveLen(1))
})
})
Context("when the request returns 500", func() {
BeforeEach(func() {
fakeServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/v1/lrps/some-process-guid/instances/some-instance-guid/stop"),
示例12:
atcServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v1/containers"),
ghttp.RespondWithJSONEncoded(200, []atc.Container{
{
ID: "handle-1",
WorkerName: "worker-name-1",
PipelineName: "pipeline-name",
StepType: "check",
ResourceName: "git-repo",
},
{
ID: "early-handle",
WorkerName: "worker-name-1",
PipelineName: "pipeline-name",
JobName: "job-name-1",
BuildName: "3",
BuildID: 123,
StepType: "get",
StepName: "git-repo",
Attempts: []int{1, 5},
},
{
ID: "other-handle",
WorkerName: "worker-name-2",
PipelineName: "pipeline-name",
JobName: "job-name-2",
BuildName: "2",
BuildID: 122,
StepType: "task",
StepName: "unit-tests",
},
{
ID: "post-handle",
WorkerName: "worker-name-3",
BuildID: 142,
StepType: "task",
StepName: "one-off",
},
}),
),
)
示例13:
server.Close()
Ω(os.Remove(tmpFile.Name())).Should(Succeed())
})
It("creates SSH scripts", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api/sessions"),
ghttp.RespondWith(204, ""),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/sessions"),
ghttp.RespondWith(200, ""),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/server_arrays"),
ghttp.RespondWith(200, serverArraysResponseBody),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/server_arrays/1/current_instances"),
ghttp.RespondWith(200, instancesResponseBody),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/servers"),
ghttp.RespondWith(200, serversResponseBody),
),
)
Ω(main).ShouldNot(Panic())
Ω(string(written)).Should(Equal(output))
})
})
示例14:
fmt.Fprintf(os.Stdout, "server addr is: "+server.Addr())
slUsername = os.Getenv("SL_USERNAME")
slAPIKey = os.Getenv("SL_API_KEY")
client = slclient.NewHttpClient(slUsername, slAPIKey, server.Addr(), "templates", false)
})
AfterEach(func() {
server.Close()
})
Context("#DoRawHttpRequest", func() {
Context("when a successful request", func() {
BeforeEach(func() {
server.CloseClientConnections()
server.AppendHandlers(
ghttp.VerifyRequest("GET", "/test"),
ghttp.VerifyBasicAuth(slUsername, slAPIKey),
)
})
It("make a request to access /test", func() {
client.DoRawHttpRequest("test", "GET", bytes.NewBufferString("random text"))
Ω(err).ShouldNot(HaveOccurred())
Ω(server.ReceivedRequests()).Should(HaveLen(1))
})
})
})
})
Context("when the target HTTP server is not stable", func() {
BeforeEach(func() {
os.Setenv("SL_API_RETRY_COUNT", "10")
示例15:
ccServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/quota_definitions"),
ghttp.RespondWith(http.StatusOK, `{
"next_url": "/v2/quota_definitions?page=2",
"resources": [
{
"metadata": { "guid": "my-quota-guid" },
"entity": {
"name": "my-remote-quota",
"memory_limit": 1024,
"instance_memory_limit": -1,
"total_routes": 123,
"total_services": 321,
"non_basic_services_allowed": true,
"app_instance_limit": 7,
"total_reserved_route_ports": 5
}
}
]
}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/quota_definitions", "page=2"),
ghttp.RespondWith(http.StatusOK, `{
"resources": [
{
"metadata": { "guid": "my-quota-guid2" },
"entity": { "name": "my-remote-quota2", "memory_limit": 1024 }
},
{
"metadata": { "guid": "my-quota-guid3" },
"entity": { "name": "my-remote-quota3", "memory_limit": 1024 }
}
]
}`),
),
)