This repository was archived by the owner on Feb 19, 2021. It is now read-only.
forked from concourse/github-release-resource
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgitlab_test.go
More file actions
129 lines (105 loc) · 2.54 KB
/
gitlab_test.go
File metadata and controls
129 lines (105 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package resource_test
import (
"net/http"
. "github.com/edtan/gitlab-release-resource"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
"github.com/xanzy/go-gitlab"
)
var _ = Describe("GitLab Client", func() {
var server *ghttp.Server
var client *GitlabClient
var source Source
BeforeEach(func() {
server = ghttp.NewServer()
})
JustBeforeEach(func() {
source.GitLabAPIURL = server.URL()
var err error
client, err = NewGitLabClient(source)
Ω(err).ShouldNot(HaveOccurred())
})
AfterEach(func() {
server.Close()
})
Context("with bad URLs", func() {
BeforeEach(func() {
source.AccessToken = "hello?"
})
It("returns an error if the API URL is bad", func() {
source.GitLabAPIURL = ":"
_, err := NewGitLabClient(source)
Ω(err).Should(HaveOccurred())
})
})
Context("with an OAuth Token", func() {
BeforeEach(func() {
source = Source{
Repository: "concourse",
AccessToken: "abc123",
}
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/releases"),
ghttp.RespondWith(200, "[]"),
ghttp.VerifyHeaderKV("Authorization", "Bearer abc123"),
),
)
})
It("sends one", func() {
_, err := client.ListTags()
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("without an OAuth Token", func() {
BeforeEach(func() {
source = Source{
Repository: "concourse",
}
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/repos/concourse/concourse/releases"),
ghttp.RespondWith(200, "[]"),
ghttp.VerifyHeader(http.Header{"Authorization": nil}),
),
)
})
It("sends one", func() {
_, err := client.ListTags()
Ω(err).ShouldNot(HaveOccurred())
})
})
Describe("GetRelease", func() {
BeforeEach(func() {
source = Source{
Repository: "concourse",
}
})
})
Describe("GetReleaseByTag", func() {
BeforeEach(func() {
source = Source{
Repository: "concourse",
}
})
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" }`),
),
)
})
It("Returns a populated github.Tag", func() {
expectedRelease := &gitlab.Tag{
Name: *gitlab.String("1"),
}
release, err := client.GetTag("some-tag")
Ω(err).ShouldNot(HaveOccurred())
Expect(release).To(Equal(expectedRelease))
})
})
})
})