Skip to content

Instantly share code, notes, and snippets.

@Wilo
Created September 30, 2021 05:49
Show Gist options
  • Select an option

  • Save Wilo/2c14298e336bcc6d3eb17cb22c433aa4 to your computer and use it in GitHub Desktop.

Select an option

Save Wilo/2c14298e336bcc6d3eb17cb22c433aa4 to your computer and use it in GitHub Desktop.

Revisions

  1. Wilo created this gist Sep 30, 2021.
    64 changes: 64 additions & 0 deletions test_impostors.go
    Original 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() {
    //
    // })
    //})
    })