-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodels_test.go
More file actions
120 lines (114 loc) · 3.05 KB
/
models_test.go
File metadata and controls
120 lines (114 loc) · 3.05 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
package resource_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
resource "github.com/telia-oss/github-pr-resource"
)
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",
GithubOrganization: "test",
UseGitHubApp: true,
PrivateKey: "key.pem",
ApplicationID: 123456,
InstallationID: 1,
},
},
{
description: "private_key App configuration values",
source: resource.Source{
Repository: "test/test",
UseGitHubApp: true,
ApplicationID: 123456,
InstallationID: 1,
},
wantErr: "private_key is required for 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.pem",
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,
GithubOrganization: "test",
PrivateKey: "key.pem",
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()
}
})
}
}