Skip to content

is there any solution to generate response in the runtime? #107

@CodeplayerGm

Description

@CodeplayerGm

since the "ReplyFunc()" provide an entrance to return a response generated by custom function. however, the "mockGithubResponseHandler" executes when the mocker is registered.
is there any way to generate response in runtime, with parameter or options for "ReplyFunc()"?

gock.New("https://github.com").
  Post("/login/oauth/access_token").
  Persist().
  MatchParams(map[string]string{
    "client_id":     "Iv1.expire0000000000",
    "client_secret": "expire0000000000000000000000000000000000",
  }).
  ReplyFunc(mockGithubResponseHandler)

func mockGithubResponseHandler(r *gock.Response) {
  r.Status(200)
  r.SetHeader("Content-type", "application/json; charset=utf-8")
  if ExpireFlag {
    r.BodyString("{expire_at: 1670000000}")
  } else {
    r.BodyString("{expire_at: 0}")
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions