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

My tests fail with GitHub Actions: mocks seem to be ignored 🀷

nicokosi opened this issue Β· comments

I cannot make tests pass in GitHub Actions for this pull request (see this comment): mocks seem OK (tests pass locally) but fail in GitHub Actions.

Any hint/tips? 😊

I did some debugging, I now understand that this is a test environment issue. The go-gh REST client library visibly needs some configuration:

RESTClient builds a client to send requests to GitHub REST API endpoints.
As part of the configuration a hostname, auth token, and default set of headers are resolved
from the gh environment configuration. These behaviors can be overridden using the opts argument.

See https://github.com/cli/go-gh/blob/c41a1271d97cf42ba0dcf94289da729cdb1554eb/gh.go#L59

Therefore, I close this issue.

PS: tests succeed locally because I have configured the GitHub CLI authentication:

$ gh auth status
github.com
  βœ“ Logged in to github.com as nicokosi (GITHUB_TOKEN)
  βœ“ Git operations for github.com configured to use ssh protocol.
  βœ“ Token: *******************

Which is used by the GitHub REST Client:

$ go test
GET /repos/acme/buzz/readme HTTP/1.1
Host: api.github.com
User-Agent: go-gh v0.0.3
Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview, application/vnd.github.antiope-preview, application/vnd.github.shadow-cat-preview
Authorization: token *******************
Content-Type: application/json; charset=utf-8
Time-Zone: Europe/Amsterdam
Accept-Encoding: gzip