h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

Home Page:https://pkg.go.dev/github.com/h2non/gock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when i access the uri twice in one test, i must gock.New(Uri) twice too

seanjoe opened this issue · comments

my func is

{
defer gock.Off()
gock.New("https//url.com").Get("path").Reply(200)
gock.New("https//url.com").Get("path").Reply(200)
gock.Observe(gock.DumpRequest)
// some test in the func maybe access url twice or more
}

if i use once, other access got Matches: false
why

commented

You could use:

gock.New("https//url.com").Get("path").Reply(200).Times(2)

For more information, see the docs:
https://godoc.org/github.com/h2non/gock#Request.Times

thank you!I think it is a temporary solution, i must estimate the times before use or set a big number in haste.

commented

Alternatively, you can use .Persist() method, which will guarantee the mock is alive unless you explicitly turn gock off. See:
https://godoc.org/github.com/h2non/gock#Request.Persist