Created
September 30, 2021 05:49
-
-
Save Wilo/2c14298e336bcc6d3eb17cb22c433aa4 to your computer and use it in GitHub Desktop.
Revisions
-
Wilo created this gist
Sep 30, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ package test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" "net/http" "os" ) type HtClient struct { cli *http.Client } func (h *HtClient) Get (uri string) (*http.Response, error) { url := os.Getenv("base_path")+uri println("url:",url) return h.cli.Get(url) } var _ = Describe("Fake Urls", func() { var( impostorServer *ghttp.Server //debe ser configurable serverBaseUrlKey = "base_path" myHtClient *HtClient ) BeforeEach(func() { impostorServer = ghttp.NewServer() impostorUrl := impostorServer.URL() println(impostorUrl) Ω(os.Setenv(serverBaseUrlKey, impostorUrl)).Should(Succeed()) myHtClient = &HtClient{ cli: http.DefaultClient, } }) Context("Fake Google", func() { It("Get Google fake", func() { impostorServer.AppendHandlers(ghttp.CombineHandlers( ghttp.VerifyRequest(http.MethodGet, "/"), ghttp.RespondWith(200, "HOLA!!"), )) resp, err := myHtClient.Get("/") Expect(resp).NotTo(BeNil()) Expect(err).To(BeNil()) }) }) //Context("Fake Yahoo", func() { // It("Get Yahoo fake", func() { // // }) //}) })