Skip to content

Commit

Permalink
test/integration: Update for API changes to fix build.
Browse files Browse the repository at this point in the history
Update code with the latest breaking API changes so that it builds
without errors.

All tests other than TestRepositories_EditBranches are passing.
To fix that test, it requires someone with expertise in protection
requests, and is out of scope of this change.
  • Loading branch information
dmitshur committed Jul 18, 2017
1 parent f292cf8 commit 4ab751a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 94 deletions.
25 changes: 13 additions & 12 deletions test/integration/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package integration

import (
"context"
"testing"

"github.com/google/go-github/github"
Expand All @@ -19,7 +20,7 @@ const (
)

func TestActivity_Starring(t *testing.T) {
stargazers, _, err := client.Activity.ListStargazers(owner, repo, nil)
stargazers, _, err := client.Activity.ListStargazers(context.Background(), owner, repo, nil)
if err != nil {
t.Fatalf("Activity.ListStargazers returned error: %v", err)
}
Expand All @@ -34,7 +35,7 @@ func TestActivity_Starring(t *testing.T) {
}

// first, check if already starred the target repository
star, _, err := client.Activity.IsStarred(owner, repo)
star, _, err := client.Activity.IsStarred(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.IsStarred returned error: %v", err)
}
Expand All @@ -43,13 +44,13 @@ func TestActivity_Starring(t *testing.T) {
}

// star the target repository
_, err = client.Activity.Star(owner, repo)
_, err = client.Activity.Star(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.Star returned error: %v", err)
}

// check again and verify starred
star, _, err = client.Activity.IsStarred(owner, repo)
star, _, err = client.Activity.IsStarred(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.IsStarred returned error: %v", err)
}
Expand All @@ -58,13 +59,13 @@ func TestActivity_Starring(t *testing.T) {
}

// unstar
_, err = client.Activity.Unstar(owner, repo)
_, err = client.Activity.Unstar(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.Unstar returned error: %v", err)
}

// check again and verify not watching
star, _, err = client.Activity.IsStarred(owner, repo)
star, _, err = client.Activity.IsStarred(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.IsStarred returned error: %v", err)
}
Expand All @@ -75,13 +76,13 @@ func TestActivity_Starring(t *testing.T) {

func deleteSubscription(t *testing.T) {
// delete subscription
_, err := client.Activity.DeleteRepositorySubscription(owner, repo)
_, err := client.Activity.DeleteRepositorySubscription(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.DeleteRepositorySubscription returned error: %v", err)
}

// check again and verify not watching
sub, _, err := client.Activity.GetRepositorySubscription(owner, repo)
sub, _, err := client.Activity.GetRepositorySubscription(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
Expand All @@ -93,13 +94,13 @@ func deleteSubscription(t *testing.T) {
func createSubscription(t *testing.T) {
// watch the target repository
sub := &github.Subscription{Subscribed: github.Bool(true)}
_, _, err := client.Activity.SetRepositorySubscription(owner, repo, sub)
_, _, err := client.Activity.SetRepositorySubscription(context.Background(), owner, repo, sub)
if err != nil {
t.Fatalf("Activity.SetRepositorySubscription returned error: %v", err)
}

// check again and verify watching
sub, _, err = client.Activity.GetRepositorySubscription(owner, repo)
sub, _, err = client.Activity.GetRepositorySubscription(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
Expand All @@ -109,7 +110,7 @@ func createSubscription(t *testing.T) {
}

func TestActivity_Watching(t *testing.T) {
watchers, _, err := client.Activity.ListWatchers(owner, repo, nil)
watchers, _, err := client.Activity.ListWatchers(context.Background(), owner, repo, nil)
if err != nil {
t.Fatalf("Activity.ListWatchers returned error: %v", err)
}
Expand All @@ -124,7 +125,7 @@ func TestActivity_Watching(t *testing.T) {
}

// first, check if already watching the target repository
sub, _, err := client.Activity.GetRepositorySubscription(owner, repo)
sub, _, err := client.Activity.GetRepositorySubscription(context.Background(), owner, repo)
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
Expand Down
37 changes: 19 additions & 18 deletions test/integration/authorizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package integration

import (
"context"
"math/rand"
"os"
"strconv"
Expand All @@ -31,23 +32,23 @@ func TestAuthorizationsBasicOperations(t *testing.T) {

client := getUserPassClient(t)

auths, resp, err := client.Authorizations.List(nil)
auths, resp, err := client.Authorizations.List(context.Background(), nil)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

initialAuthCount := len(auths)

authReq := generatePersonalAuthTokenRequest()

createdAuth, resp, err := client.Authorizations.Create(authReq)
createdAuth, resp, err := client.Authorizations.Create(context.Background(), authReq)
failOnError(t, err)
failIfNotStatusCode(t, resp, 201)

if *authReq.Note != *createdAuth.Note {
t.Fatal("Returned Authorization does not match the requested Authorization.")
}

auths, resp, err = client.Authorizations.List(nil)
auths, resp, err = client.Authorizations.List(context.Background(), nil)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -59,7 +60,7 @@ func TestAuthorizationsBasicOperations(t *testing.T) {
authUpdate := new(github.AuthorizationUpdateRequest)
authUpdate.Note = github.String("Updated note: " + randString())

updatedAuth, resp, err := client.Authorizations.Edit(*createdAuth.ID, authUpdate)
updatedAuth, resp, err := client.Authorizations.Edit(context.Background(), *createdAuth.ID, authUpdate)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -68,7 +69,7 @@ func TestAuthorizationsBasicOperations(t *testing.T) {
}

// Verify that the Get operation also reflects the update
retrievedAuth, resp, err := client.Authorizations.Get(*createdAuth.ID)
retrievedAuth, resp, err := client.Authorizations.Get(context.Background(), *createdAuth.ID)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -77,19 +78,19 @@ func TestAuthorizationsBasicOperations(t *testing.T) {
}

// Now, let's delete...
resp, err = client.Authorizations.Delete(*createdAuth.ID)
resp, err = client.Authorizations.Delete(context.Background(), *createdAuth.ID)
failOnError(t, err)
failIfNotStatusCode(t, resp, 204)

// Verify that we can no longer retrieve the auth
retrievedAuth, resp, err = client.Authorizations.Get(*createdAuth.ID)
retrievedAuth, resp, err = client.Authorizations.Get(context.Background(), *createdAuth.ID)
if err == nil {
t.Fatal("Should have failed due to 404")
}
failIfNotStatusCode(t, resp, 404)

// Verify that our count reset back to the initial value
auths, resp, err = client.Authorizations.List(nil)
auths, resp, err = client.Authorizations.List(context.Background(), nil)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -114,7 +115,7 @@ func TestAuthorizationsAppOperations(t *testing.T) {

authRequest := generateAppAuthTokenRequest(clientID, clientSecret)

createdAuth, resp, err := userAuthenticatedClient.Authorizations.GetOrCreateForApp(clientID, authRequest)
createdAuth, resp, err := userAuthenticatedClient.Authorizations.GetOrCreateForApp(context.Background(), clientID, authRequest)
failOnError(t, err)
failIfNotStatusCode(t, resp, 201)

Expand All @@ -125,7 +126,7 @@ func TestAuthorizationsAppOperations(t *testing.T) {

// Let's try the same request again, this time it should return the same
// auth instead of creating a new one
secondAuth, resp, err := userAuthenticatedClient.Authorizations.GetOrCreateForApp(clientID, authRequest)
secondAuth, resp, err := userAuthenticatedClient.Authorizations.GetOrCreateForApp(context.Background(), clientID, authRequest)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -135,7 +136,7 @@ func TestAuthorizationsAppOperations(t *testing.T) {
}

// Verify the token
appAuth, resp, err := appAuthenticatedClient.Authorizations.Check(clientID, *createdAuth.Token)
appAuth, resp, err := appAuthenticatedClient.Authorizations.Check(context.Background(), clientID, *createdAuth.Token)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

Expand All @@ -145,19 +146,19 @@ func TestAuthorizationsAppOperations(t *testing.T) {
}

// Let's verify that we get a 404 for a non-existent token
_, resp, err = appAuthenticatedClient.Authorizations.Check(clientID, InvalidTokenValue)
_, resp, err = appAuthenticatedClient.Authorizations.Check(context.Background(), clientID, InvalidTokenValue)
if err == nil {
t.Fatal("An error should have been returned because of the invalid token.")
}
failIfNotStatusCode(t, resp, 404)

// Let's reset the token
resetAuth, resp, err := appAuthenticatedClient.Authorizations.Reset(clientID, *createdAuth.Token)
resetAuth, resp, err := appAuthenticatedClient.Authorizations.Reset(context.Background(), clientID, *createdAuth.Token)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

// Let's verify that we get a 404 for a non-existent token
_, resp, err = appAuthenticatedClient.Authorizations.Reset(clientID, InvalidTokenValue)
_, resp, err = appAuthenticatedClient.Authorizations.Reset(context.Background(), clientID, InvalidTokenValue)
if err == nil {
t.Fatal("An error should have been returned because of the invalid token.")
}
Expand All @@ -174,19 +175,19 @@ func TestAuthorizationsAppOperations(t *testing.T) {
}

// Verify that the original token is now invalid
_, resp, err = appAuthenticatedClient.Authorizations.Check(clientID, *createdAuth.Token)
_, resp, err = appAuthenticatedClient.Authorizations.Check(context.Background(), clientID, *createdAuth.Token)
if err == nil {
t.Fatal("The original token should be invalid.")
}
failIfNotStatusCode(t, resp, 404)

// Check that the reset token is valid
_, resp, err = appAuthenticatedClient.Authorizations.Check(clientID, *resetAuth.Token)
_, resp, err = appAuthenticatedClient.Authorizations.Check(context.Background(), clientID, *resetAuth.Token)
failOnError(t, err)
failIfNotStatusCode(t, resp, 200)

// Let's revoke the token
resp, err = appAuthenticatedClient.Authorizations.Revoke(clientID, *resetAuth.Token)
resp, err = appAuthenticatedClient.Authorizations.Revoke(context.Background(), clientID, *resetAuth.Token)
failOnError(t, err)
failIfNotStatusCode(t, resp, 204)

Expand All @@ -195,7 +196,7 @@ func TestAuthorizationsAppOperations(t *testing.T) {
time.Sleep(time.Second * 2)

// Now, the reset token should also be invalid
_, resp, err = appAuthenticatedClient.Authorizations.Check(clientID, *resetAuth.Token)
_, resp, err = appAuthenticatedClient.Authorizations.Check(context.Background(), clientID, *resetAuth.Token)
if err == nil {
t.Fatal("The reset token should be invalid.")
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func createRandomTestRepository(owner string, autoinit bool) (*github.Repository
var repoName string
for {
repoName = fmt.Sprintf("test-%d", rand.Int())
_, resp, err := client.Repositories.Get(owner, repoName)
_, resp, err := client.Repositories.Get(context.Background(), owner, repoName)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
// found a non-existent repo, perfect
Expand All @@ -75,7 +75,7 @@ func createRandomTestRepository(owner string, autoinit bool) (*github.Repository
}

// create the repository
repo, _, err := client.Repositories.Create("", &github.Repository{Name: github.String(repoName), AutoInit: github.Bool(autoinit)})
repo, _, err := client.Repositories.Create(context.Background(), "", &github.Repository{Name: github.String(repoName), AutoInit: github.Bool(autoinit)})
if err != nil {
return nil, err
}
Expand Down
11 changes: 7 additions & 4 deletions test/integration/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

package integration

import "testing"
import (
"context"
"testing"
)

func TestIssueEvents(t *testing.T) {
events, _, err := client.Issues.ListRepositoryEvents("google", "go-github", nil)
events, _, err := client.Issues.ListRepositoryEvents(context.Background(), "google", "go-github", nil)
if err != nil {
t.Fatalf("Issues.ListRepositoryEvents returned error: %v", err)
}
Expand All @@ -19,7 +22,7 @@ func TestIssueEvents(t *testing.T) {
t.Errorf("ListRepositoryEvents returned no events")
}

events, _, err = client.Issues.ListIssueEvents("google", "go-github", 1, nil)
events, _, err = client.Issues.ListIssueEvents(context.Background(), "google", "go-github", 1, nil)
if err != nil {
t.Fatalf("Issues.ListIssueEvents returned error: %v", err)
}
Expand All @@ -28,7 +31,7 @@ func TestIssueEvents(t *testing.T) {
t.Errorf("ListIssueEvents returned no events")
}

event, _, err := client.Issues.GetEvent("google", "go-github", *events[0].ID)
event, _, err := client.Issues.GetEvent(context.Background(), "google", "go-github", *events[0].ID)
if err != nil {
t.Fatalf("Issues.GetEvent returned error: %v", err)
}
Expand Down
18 changes: 15 additions & 3 deletions test/integration/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
package integration

import (
"context"
"testing"
"time"
)

func TestEmojis(t *testing.T) {
emoji, _, err := client.ListEmojis()
emoji, _, err := client.ListEmojis(context.Background())
if err != nil {
t.Fatalf("ListEmojis returned error: %v", err)
}
Expand All @@ -28,7 +29,7 @@ func TestEmojis(t *testing.T) {
}

func TestAPIMeta(t *testing.T) {
meta, _, err := client.APIMeta()
meta, _, err := client.APIMeta(context.Background())
if err != nil {
t.Fatalf("APIMeta returned error: %v", err)
}
Expand All @@ -47,7 +48,7 @@ func TestAPIMeta(t *testing.T) {
}

func TestRateLimits(t *testing.T) {
limits, _, err := client.RateLimits()
limits, _, err := client.RateLimits(context.Background())
if err != nil {
t.Fatalf("RateLimits returned error: %v", err)
}
Expand All @@ -65,3 +66,14 @@ func TestRateLimits(t *testing.T) {
t.Errorf("Core.Reset is more than 1 minute in the past; that doesn't seem right.")
}
}

func TestListServiceHooks(t *testing.T) {
hooks, _, err := client.ListServiceHooks(context.Background())
if err != nil {
t.Fatalf("ListServiceHooks returned error: %v", err)
}

if len(hooks) == 0 {
t.Fatalf("ListServiceHooks returned no hooks")
}
}
7 changes: 5 additions & 2 deletions test/integration/pulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

package integration

import "testing"
import (
"context"
"testing"
)

func TestPullRequests_ListCommits(t *testing.T) {
commits, _, err := client.PullRequests.ListCommits("google", "go-github", 2, nil)
commits, _, err := client.PullRequests.ListCommits(context.Background(), "google", "go-github", 2, nil)
if err != nil {
t.Fatalf("PullRequests.ListCommits() returned error: %v", err)
}
Expand Down
Loading

0 comments on commit 4ab751a

Please sign in to comment.