From aff0a13d884ff5dc09bccb6c1ce081a82213bfab Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 21 Nov 2013 14:40:46 -0800 Subject: [PATCH] start of integration tests --- tests/README.md | 32 +++++++++++++++++++++++++ tests/integration/github_test.go | 40 ++++++++++++++++++++++++++++++++ tests/integration/users_test.go | 38 ++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 tests/README.md create mode 100644 tests/integration/github_test.go create mode 100644 tests/integration/users_test.go diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..7f9defd --- /dev/null +++ b/tests/README.md @@ -0,0 +1,32 @@ +go-github tests +=============== + +This directory contains additional test suites beyond the unit tests already in +[../github](../github). Whereas the unit tests run very quickly (since they +don't make any network calls) and are run by Travis on every commit, the tests +in this directory are only run manually. + +The test packages are: + +integration +----------- + +This will exercise the entire go-github library (or at least as much as is +practical) against the live GitHub API. These tests will verify that the +library is properly coded against the actual behavior of the API, and will +(hopefully) fail upon any incompatible change in the API. + +Because these tests are running using live data, there is a much higher +probability of false positives in test failures due to network issues, test +data having been changed, etc. + +These tests send real network traffic to the GitHub API and will exhaust the +default unregistered rate limit (60 requests per hour) very quickly. +Additionally, in order to test the methods that modify data, a real OAuth token +will need to be present. While the tests will try to be well-behaved in terms +of what data they modify, it is **strongly** recommended that these tests only +be run using a dedicated test account. + +Run tests using: + + GITHUB_AUTH_TOKEN=XXX go test -v ./integration diff --git a/tests/integration/github_test.go b/tests/integration/github_test.go new file mode 100644 index 0000000..6e31d88 --- /dev/null +++ b/tests/integration/github_test.go @@ -0,0 +1,40 @@ +// Copyright 2014 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package tests contains integration tests for the go-github library. +// +// These tests call the live GitHub API, and therefore require a little more +// setup to run. See https://github.com/google/go-github/tree/master/tests/integration +// for more information +package tests + +import ( + "os" + "code.google.com/p/goauth2/oauth" + + "github.com/google/go-github/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() { + token := os.Getenv("GITHUB_AUTH_TOKEN") + if token == "" { + println("!!! No OAuth token. Some tests won't run. !!!\n") + client = github.NewClient(nil) + } else { + t := &oauth.Transport{ + Token: &oauth.Token{AccessToken: token}, + } + client = github.NewClient(t.Client()) + auth = true + } +} diff --git a/tests/integration/users_test.go b/tests/integration/users_test.go new file mode 100644 index 0000000..3387bf0 --- /dev/null +++ b/tests/integration/users_test.go @@ -0,0 +1,38 @@ +// Copyright 2014 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package tests + +import "testing" + +func TestUsers_List(t *testing.T) { + u, _, err := client.Users.ListAll(nil) + if err != nil { + t.Fatalf("Users.ListAll returned error: %v", err) + } + + if len(u) == 0 { + t.Errorf("Users.ListAll returned no users") + } + + // mojombo is user #1 + if want := "mojombo"; want != *u[0].Login { + t.Errorf("user[0].Login was %q, wanted %q", *u[0].Login, want) + } +} + +func TestUsers_Get(t *testing.T) { + u, _, err := client.Users.Get("octocat") + if err != nil { + t.Fatalf("Users.Get returned error: %v", err) + } + + if want := "octocat"; want != *u.Login { + t.Errorf("user.Login was %q, wanted %q", *u.Login, want) + } + if want := "The Octocat"; want != *u.Name { + t.Errorf("user.Name was %q, wanted %q", *u.Name, want) + } +}