本文整理汇总了Golang中github.com/onsi/gomega/ghttp.Server.Addr方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Addr方法的具体用法?Golang Server.Addr怎么用?Golang Server.Addr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/onsi/gomega/ghttp.Server
的用法示例。
在下文中一共展示了Server.Addr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
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())
Eventually(session).Should(gexec.Exit(0))
Eventually(session.Out).Should(gbytes.Say("Deleted %s.", sanitizedURL))
示例2:
slclient "github.com/maximilien/softlayer-go/client"
)
var _ = Describe("A HTTP Client", func() {
var (
server *ghttp.Server
client *slclient.HttpClient
err error
slUsername, slAPIKey string
port = 9999
)
Context("when the target HTTP server is stable", func() {
BeforeEach(func() {
server = ghttp.NewServer()
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"),
示例3:
})
Context("when a client requests a local port forward", func() {
var server *ghttp.Server
BeforeEach(func() {
server = ghttp.NewServer()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/"),
ghttp.RespondWith(http.StatusOK, "hi from jim\n"),
),
)
})
It("forwards the local port to the target from the server side", func() {
lconn, err := client.Dial("tcp", server.Addr())
Expect(err).NotTo(HaveOccurred())
transport := &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
return lconn, nil
},
}
client := &http.Client{Transport: transport}
resp, err := client.Get("http://127.0.0.1/")
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
reader := bufio.NewReader(resp.Body)
line, err := reader.ReadString('\n')
示例4:
var _ = Describe("KibanaSetUtc", func() {
const (
KibanaConfigPath = "/.kibana/config/4.4.0"
KibanaIndexPath = "/.kibana"
)
var (
server *ghttp.Server
command *exec.Cmd
)
BeforeEach(func() {
server = ghttp.NewServer()
host, port, err := net.SplitHostPort(server.Addr())
Expect(err).ToNot(HaveOccurred())
command = exec.Command("./kibana_set_utc.rb")
command.Env = os.Environ()
command.Env = append(command.Env, fmt.Sprintf("ES_HOST=%s", host))
command.Env = append(command.Env, fmt.Sprintf("ES_PORT=%s", port))
})
AfterEach(func() {
server.Close()
})
Context("no index exists", func() {
BeforeEach(func() {
server.AppendHandlers(
示例5:
})
AfterEach(func() {
client.Close()
})
Context("when a client requests the execution of a command", func() {
It("runs the command", func() {
_, err := client.NewSession()
Expect(err).To(MatchError(ContainSubstring("not supported")))
})
})
Context("when a client requests a local port forward", func() {
var server *ghttp.Server
BeforeEach(func() {
server = ghttp.NewServer()
})
It("forwards the local port to the target from the server side", func() {
_, err := client.Dial("tcp", server.Addr())
Expect(err).To(MatchError(ContainSubstring("unknown channel type")))
})
It("server should not receive any connections", func() {
Expect(server.ReceivedRequests()).To(BeEmpty())
})
})
})
})