test: Simplify the function that skips integration tests by alexandear · Pull Request #3752 · google/go-github
Conversation
This PR refactors integration tests:
- Refactor
checkAuthfunction in by passing*testing.Tparameter and renaming for clarity. - Simplifying
clientandauthinitialization by usingsync.OnceValues. - Fix
TestAPIMetawhich fails if run without OAuth token.
Running integration tests locally
TestAPIMeta without token:
❯ go test -tags=integration -count=1 -v -run=TestAPIMeta ./test/integration/... === RUN TestAPIMeta --- PASS: TestAPIMeta (0.28s) PASS ok github.com/google/go-github/v75/test/integration 0.860s
TestAPIMeta with token:
❯ GITHUB_AUTH_TOKEN=ghp_... go test -tags=integration -count=1 -v -run=TestAPIMeta ./test/integration/... === RUN TestAPIMeta --- PASS: TestAPIMeta (0.28s) PASS ok github.com/google/go-github/v75/test/integration 0.860s
All tests without token:
❯ go test -tags=integration -count=1 -v ./test/integration/... === RUN TestActivity_Starring github_test.go:34: No OAuth token - skipping portions of TestActivity_Starring --- SKIP: TestActivity_Starring (0.30s) === RUN TestActivity_Watching github_test.go:34: No OAuth token - skipping portions of TestActivity_Watching --- SKIP: TestActivity_Watching (0.20s) === RUN TestOrganizationAuditLog github_test.go:34: No OAuth token - skipping portions of TestOrganizationAuditLog --- SKIP: TestOrganizationAuditLog (0.00s) === RUN TestAuthorizationsAppOperations authorizations_test.go:130: Skipping test because the required environment variable (GITHUB_CLIENT_ID) is not present. --- SKIP: TestAuthorizationsAppOperations (0.00s) === RUN TestIssueEvents --- PASS: TestIssueEvents (1.06s) === RUN TestEmojis --- PASS: TestEmojis (0.17s) === RUN TestAPIMeta --- PASS: TestAPIMeta (0.16s) === RUN TestRateLimits --- PASS: TestRateLimits (0.04s) === RUN TestPullRequests_ListCommits --- PASS: TestPullRequests_ListCommits (0.26s) === RUN TestRepositories_CRUD github_test.go:34: No OAuth token - skipping portions of TestRepositories_CRUD --- SKIP: TestRepositories_CRUD (0.00s) === RUN TestRepositories_BranchesTags --- PASS: TestRepositories_BranchesTags (0.65s) === RUN TestRepositories_EditBranches github_test.go:34: No OAuth token - skipping portions of TestRepositories_EditBranches --- SKIP: TestRepositories_EditBranches (0.00s) === RUN TestRepositories_ListByAuthenticatedUser github_test.go:34: No OAuth token - skipping portions of TestRepositories_ListByAuthenticatedUser --- SKIP: TestRepositories_ListByAuthenticatedUser (0.00s) === RUN TestRepositories_ListByUser --- PASS: TestRepositories_ListByUser (0.65s) === RUN TestRepositories_DownloadReleaseAsset github_test.go:34: No OAuth token - skipping portions of TestRepositories_DownloadReleaseAsset --- SKIP: TestRepositories_DownloadReleaseAsset (0.00s) === RUN TestRepositories_Autolinks github_test.go:34: No OAuth token - skipping portions of TestRepositories_Autolinks --- SKIP: TestRepositories_Autolinks (0.00s) === RUN TestUsers_Get --- PASS: TestUsers_Get (0.34s) === RUN TestUsers_Update github_test.go:34: No OAuth token - skipping portions of TestUsers_Update --- SKIP: TestUsers_Update (0.00s) === RUN TestUsers_Emails github_test.go:34: No OAuth token - skipping portions of TestUsers_Emails --- SKIP: TestUsers_Emails (0.00s) === RUN TestUsers_Keys github_test.go:34: No OAuth token - skipping portions of TestUsers_Keys --- SKIP: TestUsers_Keys (0.16s) PASS ok github.com/google/go-github/v75/test/integration 4.347s
Codecov Report
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.11%. Comparing base (233fe03) to head (9c77662).
⚠️ Report is 3 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@ ## master #3752 +/- ## ======================================= Coverage 91.11% 91.11% ======================================= Files 187 187 Lines 16702 16702 ======================================= Hits 15218 15218 Misses 1296 1296 Partials 188 188
☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Comment on lines +44 to +45
| if *meta.VerifiablePasswordAuthentication { | ||
| t.Error("APIMeta VerifiablePasswordAuthentication is true") |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the story with the complete reversal on this one?
Do we need to add a comment? Or was it just plain broken?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmlewis I can remove this check at all:
if *meta.VerifiablePasswordAuthentication { t.Error("APIMeta VerifiablePasswordAuthentication is true") }
The test will still be valuable.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK. We can leave it as it will be good-to-know for people who were not aware of the change in 2020.
Thank you, @alexandear!
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters