当前位置: 首页>>代码示例>>Golang>>正文


Golang Server.Addr方法代码示例

本文整理汇总了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))
开发者ID:cloudfoundry-incubator,项目名称:ltc,代码行数:30,代码来源:main_test.go

示例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"),
开发者ID:mattcui,项目名称:softlayer-go,代码行数:31,代码来源:http_client_test.go

示例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')
开发者ID:swisscom,项目名称:diego-ssh,代码行数:31,代码来源:main_test.go

示例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(
开发者ID:alphagov,项目名称:paas-cf,代码行数:30,代码来源:kibana_set_utc_test.go

示例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())
			})
		})
	})
})
开发者ID:benjaminharnett,项目名称:diego-ssh,代码行数:30,代码来源:main_windows_test.go


注:本文中的github.com/onsi/gomega/ghttp.Server.Addr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。