forked from meltwater/drone-convert-pathschanged
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
191 lines (155 loc) · 3.51 KB
/
main_test.go
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package main
import (
"testing"
)
func TestValidateSecretMissing(t *testing.T) {
s := &spec{
Secret: "",
}
got := validate(s)
want := "missing secret key"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateProviderMissing(t *testing.T) {
s := &spec{
Provider: "",
Secret: "abcdefg",
}
got := validate(s)
want := "missing provider"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateProviderUnsupported(t *testing.T) {
s := &spec{
Provider: "unsupported",
Secret: "abcdefg",
}
got := validate(s)
want := "unsupported provider"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateTokenMissing(t *testing.T) {
// bitbucket-server/stash and github use tokens for authentication
providers := []string{
"bitbucket-server",
"github",
"stash",
}
for _, provider := range providers {
s := &spec{
Provider: provider,
Secret: "abcdefg",
Token: "",
}
got := validate(s)
want := "missing token"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
}
func TestValidateBitbucketUserMissing(t *testing.T) {
s := &spec{
BitBucketUser: "",
Provider: "bitbucket",
Secret: "abcdefg",
}
got := validate(s)
want := "missing bitbucket user"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateBitbucketPasswordMissing(t *testing.T) {
s := &spec{
BitBucketUser: "centauri",
BitBucketPassword: "",
Provider: "bitbucket",
Secret: "abcdefg",
}
got := validate(s)
want := "missing bitbucket password"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateBitbucketServerAddressMissing(t *testing.T) {
s := &spec{
BitBucketAddress: "",
Provider: "bitbucket-server",
Secret: "abcdefg",
Token: "abcdefg",
}
got := validate(s)
want := "missing bitbucket server address"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
// this tests backwards compatibility with bitbucket-server for stash
func TestValidateBitbucketServerStashCompatibility(t *testing.T) {
s := &spec{
BitBucketAddress: "example.com",
Provider: "bitbucket-server",
Secret: "abcdefg",
Token: "abcdefg",
}
err := validate(s)
if err != nil {
t.Error(err)
}
// validate should replace 'Provider' with 'stash' and set 'StashServer'
want := &spec{
BitBucketAddress: "example.com",
Provider: "stash",
StashServer: "example.com",
Secret: "abcdefg",
Token: "abcdefg",
}
if *s != *want {
t.Errorf("wanted %+v, got %+v", *want, *s)
}
}
func TestValidateStashServerMissing(t *testing.T) {
s := &spec{
Provider: "stash",
Secret: "abcdefg",
StashServer: "",
Token: "abcdefg",
}
got := validate(s)
want := "missing stash server"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateGiteeMissing(t *testing.T) {
s := &spec{
Secret: "abcdefg",
Provider: "gitee",
Token: "",
}
got := validate(s)
want := "missing gitee token"
if got.Error() != want {
t.Errorf("wanted %s, got %s", want, got)
}
}
func TestValidateForcedDroneAuth(t *testing.T) {
// drone uses a secret for authentication
s := &spec{
Secret: "abcdefg",
Provider: "github",
UseDroneAuth: true,
}
got := validate(s)
if got != nil {
t.Errorf("wanted no errors, got %s", got)
}
}