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
For info, here is my environment fix:
nicokosi/gh-collab-scanner@4854d1f
See the documentation: https://docs.github.com/en/actions/using-workflows/using-github-cli-in-workflows. π