unit-test rate limit behavior

This commit is contained in:
Evan Short
2016-02-05 16:40:00 -08:00
parent 91b8f79018
commit 742ade538f

View File

@@ -76,4 +76,76 @@ var _ = Describe("GitHub Client", func() {
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Describe("GetRelease", func() {
BeforeEach(func() {
source = Source{
User: "concourse",
Repository: "concourse",
}
})
Context("When GitHub's rate limit has been exceeded", func() {
BeforeEach(func() {
rateLimitResponse := `{
"message": "API rate limit exceeded for 127.0.0.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
"documentation_url": "https://developer.github.com/v3/#rate-limiting"
}`
rateLimitHeaders := http.Header(map[string][]string{
"X-RateLimit-Limit": {"60"},
"X-RateLimit-Remaining": {"0"},
"X-RateLimit-Reset": {"1377013266"},
})
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/releases/20"),
ghttp.RespondWith(403, rateLimitResponse, rateLimitHeaders),
),
)
})
It("Returns an appropriate error", func() {
_, err := client.GetRelease(20)
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(ContainSubstring("API rate limit exceeded for 127.0.0.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)"))
})
})
})
Describe("GetReleaseByTag", func() {
BeforeEach(func() {
source = Source{
User: "concourse",
Repository: "concourse",
}
})
Context("When GitHub's rate limit has been exceeded", func() {
BeforeEach(func() {
rateLimitResponse := `{
"message": "API rate limit exceeded for 127.0.0.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
"documentation_url": "https://developer.github.com/v3/#rate-limiting"
}`
rateLimitHeaders := http.Header(map[string][]string{
"X-RateLimit-Limit": {"60"},
"X-RateLimit-Remaining": {"0"},
"X-RateLimit-Reset": {"1377013266"},
})
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/releases/tags/some-tag"),
ghttp.RespondWith(403, rateLimitResponse, rateLimitHeaders),
),
)
})
It("Returns an appropriate error", func() {
_, err := client.GetReleaseByTag("some-tag")
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(ContainSubstring("API rate limit exceeded for 127.0.0.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)"))
})
})
})
}) })