Created
September 30, 2021 05:49
-
-
Save Wilo/2c14298e336bcc6d3eb17cb22c433aa4 to your computer and use it in GitHub Desktop.
impostors go
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 characters
| 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() { | |
| // | |
| // }) | |
| //}) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment