Begin working on tests
This commit is contained in:
178
gitlab_test.go
178
gitlab_test.go
@@ -3,18 +3,18 @@ package resource_test
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
. "github.com/concourse/github-release-resource"
|
||||
. "github.com/edtan/gitlab-release-resource"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/onsi/gomega/ghttp"
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
var _ = Describe("GitHub Client", func() {
|
||||
var _ = Describe("GitLab Client", func() {
|
||||
var server *ghttp.Server
|
||||
var client *GitHubClient
|
||||
var client *GitlabClient
|
||||
var source Source
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -22,10 +22,10 @@ var _ = Describe("GitHub Client", func() {
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
source.GitHubAPIURL = server.URL()
|
||||
source.GitLabAPIURL = server.URL()
|
||||
|
||||
var err error
|
||||
client, err = NewGitHubClient(source)
|
||||
client, err = NewGitLabClient(source)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
|
||||
@@ -39,16 +39,9 @@ var _ = Describe("GitHub Client", func() {
|
||||
})
|
||||
|
||||
It("returns an error if the API URL is bad", func() {
|
||||
source.GitHubAPIURL = ":"
|
||||
source.GitLabAPIURL = ":"
|
||||
|
||||
_, err := NewGitHubClient(source)
|
||||
Ω(err).Should(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns an error if the API URL is bad", func() {
|
||||
source.GitHubUploadsURL = ":"
|
||||
|
||||
_, err := NewGitHubClient(source)
|
||||
_, err := NewGitLabClient(source)
|
||||
Ω(err).Should(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -56,7 +49,6 @@ var _ = Describe("GitHub Client", func() {
|
||||
Context("with an OAuth Token", func() {
|
||||
BeforeEach(func() {
|
||||
source = Source{
|
||||
Owner: "concourse",
|
||||
Repository: "concourse",
|
||||
AccessToken: "abc123",
|
||||
}
|
||||
@@ -71,7 +63,7 @@ var _ = Describe("GitHub Client", func() {
|
||||
})
|
||||
|
||||
It("sends one", func() {
|
||||
_, err := client.ListReleases()
|
||||
_, err := client.ListTags()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -79,7 +71,6 @@ var _ = Describe("GitHub Client", func() {
|
||||
Context("without an OAuth Token", func() {
|
||||
BeforeEach(func() {
|
||||
source = Source{
|
||||
Owner: "concourse",
|
||||
Repository: "concourse",
|
||||
}
|
||||
|
||||
@@ -93,28 +84,7 @@ var _ = Describe("GitHub Client", func() {
|
||||
})
|
||||
|
||||
It("sends one", func() {
|
||||
_, err := client.ListReleases()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("when the source is configured with the deprecated user field", func() {
|
||||
BeforeEach(func() {
|
||||
source = Source{
|
||||
User: "some-owner",
|
||||
Repository: "some-repo",
|
||||
}
|
||||
|
||||
server.AppendHandlers(
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("GET", "/repos/some-owner/some-repo/releases"),
|
||||
ghttp.RespondWith(200, "[]"),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("uses the provided user as the owner", func() {
|
||||
_, err := client.ListReleases()
|
||||
_, err := client.ListTags()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -122,154 +92,38 @@ var _ = Describe("GitHub Client", func() {
|
||||
Describe("GetRelease", func() {
|
||||
BeforeEach(func() {
|
||||
source = Source{
|
||||
Owner: "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{
|
||||
Owner: "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.)"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("When GitHub responds successfully", func() {
|
||||
Context("When GitLab responds successfully", func() {
|
||||
BeforeEach(func() {
|
||||
server.AppendHandlers(
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/releases/tags/some-tag"),
|
||||
ghttp.RespondWith(200, `{ "id": 1 }`),
|
||||
ghttp.RespondWith(200, `{ "id": "1" }`),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("Returns a populated github.RepositoryRelease", func() {
|
||||
expectedRelease := &github.RepositoryRelease{
|
||||
ID: github.Int(1),
|
||||
It("Returns a populated github.Tag", func() {
|
||||
expectedRelease := &gitlab.Tag{
|
||||
Name: *gitlab.String("1"),
|
||||
}
|
||||
|
||||
release, err := client.GetReleaseByTag("some-tag")
|
||||
release, err := client.GetTag("some-tag")
|
||||
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Expect(release).To(Equal(expectedRelease))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetRef", func() {
|
||||
BeforeEach(func() {
|
||||
source = Source{
|
||||
Owner: "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/git/refs/tags/some-tag"),
|
||||
ghttp.RespondWith(403, rateLimitResponse, rateLimitHeaders),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("Returns an appropriate error", func() {
|
||||
_, err := client.GetRef("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.)"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("When GitHub responds successfully", func() {
|
||||
BeforeEach(func() {
|
||||
server.AppendHandlers(
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/git/refs/tags/some-tag"),
|
||||
ghttp.RespondWith(200, `{ "ref": "refs/tags/some-tag" }`),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
It("Returns a populated github.Reference", func() {
|
||||
expectedReference := &github.Reference{
|
||||
Ref: github.String("refs/tags/some-tag"),
|
||||
}
|
||||
|
||||
reference, err := client.GetRef("some-tag")
|
||||
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Expect(reference).To(Equal(expectedReference))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user