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() { // // }) //}) })