Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My tests fail with GitHub Actions: mocks seem to be ignored 🤷 #98

Closed
nicokosi opened this issue Mar 1, 2022 · 2 comments
Closed

Comments

@nicokosi
Copy link

nicokosi commented Mar 1, 2022

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? 😊

@nicokosi nicokosi changed the title Fails with GitHub Actions My tests fail with GitHub Actions: mocks seems ignored 🤷 Mar 1, 2022
@nicokosi nicokosi changed the title My tests fail with GitHub Actions: mocks seems ignored 🤷 My tests fail with GitHub Actions: mocks seem to be ignored 🤷 Mar 1, 2022
@nicokosi
Copy link
Author

nicokosi commented Mar 2, 2022

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

@nicokosi nicokosi closed this as completed Mar 2, 2022
@nicokosi
Copy link
Author

nicokosi commented Mar 2, 2022

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. 📖

heaths added a commit to heaths/gh-projects that referenced this issue Jun 19, 2022
heaths added a commit to heaths/gh-projects that referenced this issue Jun 19, 2022
* Parallelize adding/removing issues and add tests

Introduces tests using `gock` since cli/cli and cli/go-gh are deprecating their `httpmocks` in favor of `gock`.

* Resolve auth error with mocks

Thanks to h2non/gock#98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant