Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions test/integration/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func TestActivity_Starring(t *testing.T) {
}

// the rest of the tests requires auth
if !checkAuth("TestActivity_Starring") {
return
}
skipIfMissingAuth(t)

// first, check if already starred the target repository
star, _, err := client.Activity.IsStarred(t.Context(), owner, repo)
Expand Down Expand Up @@ -119,9 +117,7 @@ func TestActivity_Watching(t *testing.T) {
}

// the rest of the tests requires auth
if !checkAuth("TestActivity_Watching") {
return
}
skipIfMissingAuth(t)

// first, check if already watching the target repository
sub, _, err := client.Activity.GetRepositorySubscription(t.Context(), owner, repo)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/audit_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
// Note: Org must be part of an enterprise.
// Test requires auth - set env var GITHUB_AUTH_TOKEN.
func TestOrganizationAuditLog(t *testing.T) {
skipIfMissingAuth(t)

org := "example_org"
entries, _, err := client.Organizations.GetAuditLog(t.Context(), org, nil)
if err != nil {
Expand Down
28 changes: 10 additions & 18 deletions test/integration/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,27 @@ import (
"math/rand"
"net/http"
"os"
"sync"
"testing"

"github.com/google/go-github/v75/github"
)

var (
client *github.Client

// auth indicates whether tests are being run with an OAuth token.
// Tests can use this flag to skip certain tests when run without auth.
auth bool
)

func init() {
// client is a github.Client with the default http.Client. It is authorized if auth is true.
// auth indicates whether tests are being run with an OAuth token
// that is defined in the GITHUB_AUTH_TOKEN environment variable.
var client, auth = sync.OnceValues(func() (*github.Client, bool) {
token := os.Getenv("GITHUB_AUTH_TOKEN")
if token == "" {
fmt.Print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
client = github.NewClient(nil).WithAuthToken(token)
auth = true
return github.NewClient(nil), false
}
}
return github.NewClient(nil).WithAuthToken(token), true
})()

func checkAuth(name string) bool {
func skipIfMissingAuth(t *testing.T) {
if !auth {
fmt.Printf("No auth - skipping portions of %v\n", name)
t.Skipf("No OAuth token - skipping portions of %v\n", t.Name())
}
return auth
}

func createRandomTestRepository(t *testing.T, owner string, autoinit bool) *github.Repository {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestAPIMeta(t *testing.T) {
t.Error("Get returned no git addresses")
}

if !*meta.VerifiablePasswordAuthentication {
t.Error("APIMeta VerifiablePasswordAuthentication is false")
if *meta.VerifiablePasswordAuthentication {
t.Error("APIMeta VerifiablePasswordAuthentication is true")
Comment on lines +44 to +45
Copy link
Collaborator

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?

Copy link
Contributor Author

@alexandear alexandear Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Collaborator

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!

}
}

Expand Down
20 changes: 5 additions & 15 deletions test/integration/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
)

func TestRepositories_CRUD(t *testing.T) {
if !checkAuth("TestRepositories_CRUD") {
return
}
skipIfMissingAuth(t)

repo := createRandomTestRepository(t, "", true)

Expand Down Expand Up @@ -75,9 +73,7 @@ func TestRepositories_BranchesTags(t *testing.T) {
}

func TestRepositories_EditBranches(t *testing.T) {
if !checkAuth("TestRepositories_EditBranches") {
return
}
skipIfMissingAuth(t)

repo := createRandomTestRepository(t, "", true)

Expand Down Expand Up @@ -148,9 +144,7 @@ func TestRepositories_EditBranches(t *testing.T) {
}

func TestRepositories_ListByAuthenticatedUser(t *testing.T) {
if !checkAuth("TestRepositories_ListByAuthenticatedUser") {
return
}
skipIfMissingAuth(t)

_, _, err := client.Repositories.ListByAuthenticatedUser(t.Context(), nil)
if err != nil {
Expand All @@ -177,9 +171,7 @@ func TestRepositories_ListByUser(t *testing.T) {
}

func TestRepositories_DownloadReleaseAsset(t *testing.T) {
if !checkAuth("TestRepositories_DownloadReleaseAsset") {
return
}
skipIfMissingAuth(t)

rc, _, err := client.Repositories.DownloadReleaseAsset(t.Context(), "andersjanmyr", "goose", 484892, http.DefaultClient)
if err != nil {
Expand All @@ -193,9 +185,7 @@ func TestRepositories_DownloadReleaseAsset(t *testing.T) {
}

func TestRepositories_Autolinks(t *testing.T) {
if !checkAuth("TestRepositories_Autolinks") {
return
}
skipIfMissingAuth(t)

repo := createRandomTestRepository(t, "", true)

Expand Down
12 changes: 3 additions & 9 deletions test/integration/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func TestUsers_Get(t *testing.T) {
}

func TestUsers_Update(t *testing.T) {
if !checkAuth("TestUsers_Get") {
return
}
skipIfMissingAuth(t)

u, _, err := client.Users.Get(t.Context(), "")
if err != nil {
Expand Down Expand Up @@ -93,9 +91,7 @@ func TestUsers_Update(t *testing.T) {
}

func TestUsers_Emails(t *testing.T) {
if !checkAuth("TestUsers_Emails") {
return
}
skipIfMissingAuth(t)

emails, _, err := client.Users.ListEmails(t.Context(), nil)
if err != nil {
Expand Down Expand Up @@ -169,9 +165,7 @@ func TestUsers_Keys(t *testing.T) {
}

// the rest of the tests requires auth
if !checkAuth("TestUsers_Keys") {
return
}
skipIfMissingAuth(t)

// TODO: make this integration test work for any authenticated user.
keys, _, err = client.Users.ListKeys(t.Context(), "", nil)
Expand Down
Loading