github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/thirdparty/github_test.go (about)

     1  package thirdparty
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/evergreen-ci/evergreen/testutil"
     8  	. "github.com/smartystreets/goconvey/convey"
     9  )
    10  
    11  var repoKind = "github"
    12  
    13  func TestGetGithubAPIStatus(t *testing.T) {
    14  	Convey("Getting Github API status should yield expected response", t, func() {
    15  		status, err := GetGithubAPIStatus()
    16  		So(err, ShouldBeNil)
    17  		So(status, ShouldBeIn, []string{GithubAPIStatusGood, GithubAPIStatusMinor, GithubAPIStatusMajor})
    18  	})
    19  }
    20  
    21  func TestVerifyGithubAPILimitHeader(t *testing.T) {
    22  	Convey("With an http.Header", t, func() {
    23  		header := http.Header{}
    24  		Convey("An empty limit header should return an error", func() {
    25  			header["X-Ratelimit-Remaining"] = []string{"5000"}
    26  			rem, err := verifyGithubAPILimitHeader(header)
    27  			So(err, ShouldNotBeNil)
    28  			So(rem, ShouldEqual, 0)
    29  		})
    30  
    31  		Convey("An empty remaining header should return an error", func() {
    32  			header["X-Ratelimit-Limit"] = []string{"5000"}
    33  			delete(header, "X-Ratelimit-Remaining")
    34  			rem, err := verifyGithubAPILimitHeader(header)
    35  			So(err, ShouldNotBeNil)
    36  			So(rem, ShouldEqual, 0)
    37  		})
    38  
    39  		Convey("It should return remaining", func() {
    40  			header["X-Ratelimit-Limit"] = []string{"5000"}
    41  			header["X-Ratelimit-Remaining"] = []string{"4000"}
    42  			rem, err := verifyGithubAPILimitHeader(header)
    43  			So(err, ShouldBeNil)
    44  			So(rem, ShouldEqual, 4000)
    45  		})
    46  	})
    47  }
    48  
    49  func TestCheckGithubAPILimit(t *testing.T) {
    50  	testutil.ConfigureIntegrationTest(t, testConfig, "TestCheckGithubAPILimit")
    51  	Convey("Getting Github API limit should succeed", t, func() {
    52  		rem, err := CheckGithubAPILimit(testConfig.Credentials[repoKind])
    53  		// Without a proper token, the API limit is small
    54  		So(rem, ShouldBeGreaterThan, 100)
    55  		So(err, ShouldBeNil)
    56  	})
    57  }