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:%s@%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))
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"),
}) 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')
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(
}) 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()) }) }) }) })