forked from fatmcgav-depop/github-pr-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels_test.go
More file actions
146 lines (139 loc) · 4.61 KB
/
Copy pathmodels_test.go
File metadata and controls
146 lines (139 loc) · 4.61 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package resource_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
resource "github.com/telia-oss/github-pr-resource"
)
var key = `-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA0BUezcR7uycgZsfVLlAf4jXP7uFpVh4geSTY39RvYrAll0yh
q7uiQypP2hjQJ1eQXZvkAZx0v9lBYJmX7e0HiJckBr8+/O2kARL+GTCJDJZECpjy
97yylbzGBNl3s76fZ4CJ+4f11fCh7GJ3BJkMf9NFhe8g1TYS0BtSd/sauUQEuG/A
3fOJxKTNmICZr76xavOQ8agA4yW9V5hKcrbHzkfecg/sQsPMmrXixPNxMsqyOMmg
jdJ1aKr7ckEhd48ft4bPMO4DtVL/XFdK2wJZZ0gXJxWiT1Ny41LVql97Odm+OQyx
tcayMkGtMb1nwTcVVl+RG2U5E1lzOYpcQpyYFQIDAQABAoIBAAfUY55WgFlgdYWo
i0r81NZMNBDHBpGo/IvSaR6y/aX2/tMcnRC7NLXWR77rJBn234XGMeQloPb/E8iw
vtjDDH+FQGPImnQl9P/dWRZVjzKcDN9hNfNAdG/R9JmGHUz0JUddvNNsIEH2lgEx
C01u/Ntqdbk+cDvV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=
-----END RSA PRIVATE KEY-----`
func TestSource(t *testing.T) {
tests := []struct {
description string
source resource.Source
wantErr string
}{
{
description: "validate passes",
source: resource.Source{
AccessToken: "123456",
Repository: "test/test",
},
},
{
description: "should have an access_token",
source: resource.Source{
Repository: "test/test",
},
wantErr: "access_token must be set if not using GitHub App authentication",
},
{
description: "should have a repository",
source: resource.Source{
AccessToken: "123456",
},
wantErr: "repository must be set",
},
{
description: "should support GitHub App authentication",
source: resource.Source{
Repository: "test/test",
UseGitHubApp: true,
PrivateKey: key,
ApplicationID: 123456,
InstallationID: 1,
},
},
{
description: "requires a private_key GitHub App configuration values",
source: resource.Source{
Repository: "test/test",
UseGitHubApp: true,
ApplicationID: 123456,
InstallationID: 1,
},
wantErr: "private_key should be supplied if using GitHub App authentication",
},
{
description: "requires an application_id and installation_id GitHub App configuration values",
source: resource.Source{
Repository: "test/test",
UseGitHubApp: true,
PrivateKey: key,
ApplicationID: 123456,
},
wantErr: "application_id and installation_id must be set if using GitHub App authentication",
},
{
description: "should not have an access_token when using GitHub App authentication",
source: resource.Source{
Repository: "test/test",
UseGitHubApp: true,
PrivateKey: key,
ApplicationID: 123456,
InstallationID: 1,
AccessToken: "123456",
},
wantErr: "access_token is not required when using GitHub App authentication",
},
{
description: "requires v3_endpoint when v4_endpoint is set",
source: resource.Source{
AccessToken: "123456",
Repository: "test/test",
V3Endpoint: "https://github.com/v3",
},
wantErr: "v4_endpoint must be set together with v3_endpoint",
},
{
description: "requires v4_endpoint when v3_endpoint is set",
source: resource.Source{
AccessToken: "123456",
Repository: "test/test",
V4Endpoint: "https://github.com/v4",
},
wantErr: "v3_endpoint must be set together with v4_endpoint",
},
}
for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
err := tc.source.Validate()
if tc.wantErr != "" {
if err == nil {
t.Logf("Expected error '%s', got nothing", tc.wantErr)
t.Fail()
}
assert.EqualError(t, err, tc.wantErr, fmt.Sprintf("Expected '%s', got '%s'", tc.wantErr, err))
}
if tc.wantErr == "" && err != nil {
t.Logf("Got an error when none expected: %s", err)
t.Fail()
}
})
}
}