本文整理汇总了Golang中github.com/onsi/gomega/ghttp.Server.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Close方法的具体用法?Golang Server.Close怎么用?Golang Server.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/onsi/gomega/ghttp.Server
的用法示例。
在下文中一共展示了Server.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
client = holler.NewYeller(
"api-token", "staging",
holler.UseCollectors(
collector.URL(),
otherCollector.URL(),
),
holler.UseRandomSource(
rand.NewSource(1),
),
)
})
AfterEach(func() {
if collector != nil {
collector.Close()
}
if otherCollector != nil {
otherCollector.Close()
}
})
Context("when the first collector works", func() {
BeforeEach(func() {
collector.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/api-token"),
ghttp.VerifyJSON(requestJSON("disaster")),
ghttp.RespondWith(200, ""),
),
示例2:
repo ServiceKeyRepository
)
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
configRepo.SetAccessToken("BEARER my_access_token")
ccServer = ghttp.NewServer()
configRepo.SetApiEndpoint(ccServer.URL())
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))
示例3:
"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"))
Eventually(session.Out).Should(Say("OK"))
Eventually(session).Should(Exit(0))
})
})
It("sets SSL Disabled in the config file to true", func() {
示例4:
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))
})
It("returns the one time code", func() {
code, err := authRepo.Authorize("auth-token")
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal("F45jH"))
})
Context("when the authentication endpoint is malformed", func() {
示例5:
LogLevel: "debug",
ConsulCluster: consulRunner.ConsulCluster(),
PollingInterval: pollingInterval,
EvacuationTimeout: evacuationTimeout,
},
)
})
JustBeforeEach(func() {
runner.Start()
})
AfterEach(func(done Done) {
close(flushEvents)
runner.KillWithFire()
fakeGarden.Close()
close(done)
})
Context("when Garden is available", func() {
BeforeEach(func() {
fakeGarden.Start()
})
Describe("when an interrupt signal is sent to the representative", func() {
JustBeforeEach(func() {
if runtime.GOOS == "windows" {
Skip("Interrupt isn't supported on windows")
}
runner.Stop()
示例6:
etcdRunner.Reset()
bbsRunner = bbstestrunner.New(bbsBinPath, bbsArgs)
bbsProcess = ginkgomon.Invoke(bbsRunner)
consulSession = consulRunner.NewSession("a-session")
})
var _ = AfterEach(func() {
if bbsProcess != nil {
ginkgomon.Kill(bbsProcess)
}
})
var _ = SynchronizedAfterSuite(func() {
if etcdRunner != nil {
etcdRunner.KillWithFire()
}
if consulRunner != nil {
consulRunner.Stop()
}
if runner != nil {
runner.KillWithFire()
}
if auctioneerServer != nil {
auctioneerServer.Close()
}
}, func() {
gexec.CleanupBuildArtifacts()
})
示例7: Change
team concourse.Team
)
var _ = BeforeEach(func() {
atcServer = ghttp.NewServer()
client = concourse.NewClient(
atcServer.URL(),
&http.Client{},
)
team = client.Team("some-team")
})
var _ = AfterEach(func() {
atcServer.Close()
})
func Change(fn func() int) *changeMatcher {
return &changeMatcher{
fn: fn,
}
}
type changeMatcher struct {
fn func() int
amount int
before int
after int
}
示例8:
root *httptest.Server
recorder *ghttp.Server
)
BeforeEach(func() {
root = startSimpleBackend("fallthrough")
recorder = startRecordingBackend()
addBackend("root", root.URL)
addBackend("other", recorder.URL())
addBackendRoute("/", "root", "prefix")
addBackendRoute("/foo/bar", "other", "prefix")
reloadRoutes()
})
AfterEach(func() {
root.Close()
recorder.Close()
})
It("should not be redirected by our simple test backend", func() {
resp := routerRequest("//")
Expect(readBody(resp)).To(Equal("fallthrough"))
})
It("should not be redirected by our recorder backend", func() {
resp := routerRequest("/foo/bar/baz//qux")
Expect(resp.StatusCode).To(Equal(200))
Expect(recorder.ReceivedRequests()).To(HaveLen(1))
Expect(recorder.ReceivedRequests()[0].URL.Path).To(Equal("/foo/bar/baz//qux"))
})
It("should collapse double slashes when looking up route, but pass request as-is", func() {
示例9:
ghttp.VerifyRequest("POST", "/builds/some-guid/abort"),
)
})
JustBeforeEach(func() {
var err error
req, err := http.NewRequest("POST", server.URL+"/api/v1/builds/128/abort", nil)
Expect(err).NotTo(HaveOccurred())
response, err = client.Do(req)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
abortTarget.Close()
})
Context("when authenticated", func() {
BeforeEach(func() {
authValidator.IsAuthenticatedReturns(true)
})
Context("when the build can be found", func() {
BeforeEach(func() {
buildsDB.GetBuildReturns(db.Build{
ID: 128,
Status: db.StatusStarted,
}, true, nil)
})
示例10:
It("responds with correct body", func() {
assertBodyEquals(resp.Body, RespBody)
})
})
Context("when socket in reques URI is incorrect", func() {
It("errors", func() {
resp, err = client.Get("unix:///fake/socket.sock/_ping")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Wrong unix socket"))
})
})
AfterEach(func() {
unixSocketServer.Close()
})
})
Context("with no server listening", func() {
BeforeEach(func() {
socket = "/not/existing.sock"
client = http.Client{Transport: New(socket)}
})
It("errors", func() {
_, err := client.Get("unix:///not/existing.sock/_ping")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Or(
ContainSubstring(fmt.Sprintf("dial unix %s: connect: no such file or directory", socket)),
ContainSubstring(fmt.Sprintf("dial unix %s: no such file or directory", socket)),
示例11:
var _ = Describe("DockerSessionFactory", func() {
Describe("MakeSession", func() {
var (
registryHost string
dockerRegistryServer *ghttp.Server
sessionFactory docker_metadata_fetcher.DockerSessionFactory
)
BeforeEach(func() {
sessionFactory = docker_metadata_fetcher.NewDockerSessionFactory()
dockerRegistryServer = ghttp.NewServer()
})
AfterEach(func() {
dockerRegistryServer.Close()
})
Describe("creating registry sessions", func() {
BeforeEach(func() {
parts, err := url.Parse(dockerRegistryServer.URL())
Expect(err).NotTo(HaveOccurred())
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)
示例12:
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
"github.com/rightscale/gdo/middleware"
)
const (
doGetDropletActions = `{"actions":[{"id":48912908,"status":"completed","type":"create","started_at":"2015-04-24T22:55:43Z","completed_at":"2015-04-24T22:56:39Z","resource_id":5004436,"resource_type":"droplet","region":{"name":"New York 3","slug":"nyc3","sizes":["512mb","1gb","2gb","4gb","8gb","16gb","32gb","48gb","64gb"],"features":["virtio","private_networking","backups","ipv6","metadata"],"available":true},"region_slug":"nyc3"}],"links":{},"meta":{"total":1}}`
doGetDropletActionsEmpty = `{"actions":[],"links":{},"meta":{"total":0}}`
doGetDropletAction = `{"action":{"id":48913731,"status":"completed","type":"power_off","started_at":"2015-04-24T23:11:41Z","completed_at":"2015-04-24T23:12:01Z","resource_id":5004436,"resource_type":"droplet","region":{"name":"New York 3","slug":"nyc3","sizes":["512mb","1gb","2gb","4gb","8gb","16gb","32gb","48gb","64gb"],"features":["virtio","private_networking","backups","ipv6","metadata"],"available":true},"region_slug":"nyc3"}}`
)
var _ = Describe("droplet_actions", func() {
var do *ghttp.Server
var client *GDOClient
BeforeEach(func() {
do = ghttp.NewServer()
u, err := url.Parse(do.URL())
Expect(err).NotTo(HaveOccurred())
middleware.DOBaseURL = u
client = NewGDOClient()
})
AfterEach(func() {
do.Close()
})
})
示例13: createConfig
routingAPIArgs = testrunner.Args{
Port: routingAPIPort,
IP: routingAPIIP,
SystemDomain: routingAPISystemDomain,
ConfigPath: createConfig(),
EtcdCluster: etcdUrl,
DevMode: true,
}
})
var _ = AfterEach(func() {
etcdAdapter.Disconnect()
etcdRunner.Reset()
etcdRunner.Stop()
oauthServer.Close()
})
func createConfig() string {
type customConfig struct {
Port int
UAAPort string
}
actualStatsdConfig := customConfig{Port: 8125 + GinkgoParallelNode(), UAAPort: oauthServerPort}
workingDir, _ := os.Getwd()
template, err := template.ParseFiles(workingDir + "/../../example_config/example_template.yml")
Expect(err).NotTo(HaveOccurred())
configFilePath := fmt.Sprintf("/tmp/example_%d.yml", GinkgoParallelNode())
configFile, err := os.Create(configFilePath)
Expect(err).NotTo(HaveOccurred())
示例14:
BucketName: "blah-bucket",
Endpoint: testS3Server.URL(),
AccessKeyID: "ABCD",
SecretAccessKey: "ABCD",
ComparisonFile: comparisonFilePath,
}
})
JustBeforeEach(func() {
runner = NewThroughputRamp(binPath, runnerArgs)
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
示例15:
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
configRepo.SetAccessToken("BEARER my_access_token")
gateway := net.NewCloudControllerGateway(configRepo, time.Now, new(terminalfakes.FakeUI), new(tracefakes.FakePrinter))
repo = NewCloudControllerStackRepository(configRepo, gateway)
})
BeforeEach(func() {
testServer = ghttp.NewServer()
configRepo.SetAPIEndpoint(testServer.URL())
})
AfterEach(func() {
if testServer != nil {
testServer.Close()
}
})
Describe("FindByName", func() {
Context("when a stack exists", func() {
BeforeEach(func() {
testServer.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/v2/stacks", "q=name%3Alinux"),
ghttp.RespondWith(http.StatusOK, `{
"resources": [
{
"metadata": { "guid": "custom-linux-guid" },
"entity": { "name": "custom-linux" }
}