Browse Source

use golang.org/x/oauth2 for field and integration tests

Will Norris 11 years ago
parent
commit
e8719935a2
2 changed files with 30 additions and 10 deletions
  1. +15
    -5
      tests/fields/fields.go
  2. +15
    -5
      tests/integration/github_test.go

+ 15
- 5
tests/fields/fields.go View File

@ -24,8 +24,8 @@ import (
"reflect"
"strings"
"code.google.com/p/goauth2/oauth"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
var (
@ -38,6 +38,16 @@ var (
skipURLs = flag.Bool("skip_urls", false, "skip url fields")
)
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error) {
return t.token, nil
}
func main() {
flag.Parse()
@ -46,10 +56,10 @@ func main() {
print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
}
client = github.NewClient(t.Client())
tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{
&oauth2.Token{AccessToken: token},
})
client = github.NewClient(tc)
auth = true
}


+ 15
- 5
tests/integration/github_test.go View File

@ -13,8 +13,8 @@ import (
"fmt"
"os"
"code.google.com/p/goauth2/oauth"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
var (
@ -25,16 +25,26 @@ var (
auth bool
)
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error) {
return t.token, nil
}
func init() {
token := os.Getenv("GITHUB_AUTH_TOKEN")
if token == "" {
print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
}
client = github.NewClient(t.Client())
tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{
&oauth2.Token{AccessToken: token},
})
client = github.NewClient(tc)
auth = true
}
}


Loading…
Cancel
Save