forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_app_test.go
87 lines (68 loc) · 2 KB
/
github_app_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
package evergreen
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
"go.mongodb.org/mongo-driver/bson"
)
type installationSuite struct {
ctx context.Context
cancel context.CancelFunc
suite.Suite
}
func TestGithubInstallationSuite(t *testing.T) {
suite.Run(t, new(installationSuite))
}
func (s *installationSuite) SetupTest() {
s.ctx, s.cancel = context.WithCancel(context.Background())
_, err := GetEnvironment().DB().Collection(GitHubAppCollection).DeleteMany(s.ctx, bson.M{})
s.NoError(err)
}
func (s *installationSuite) TearDownTest() {
s.cancel()
}
func (s *installationSuite) TestUpsert() {
installation := GitHubAppInstallation{
Owner: "evergreen-ci",
Repo: "evergreen",
InstallationID: 0,
}
s.NoError(installation.Upsert(s.ctx))
installation.Owner = ""
err := installation.Upsert(s.ctx)
s.Error(err)
s.Equal("Owner and repository must not be empty strings", err.Error())
installation.Owner = "evergreen-ci"
installation.Repo = ""
err = installation.Upsert(s.ctx)
s.Error(err)
s.Equal("Owner and repository must not be empty strings", err.Error())
installationWithInstallationAndAppID := GitHubAppInstallation{
Owner: "evergreen-ci",
Repo: "evergreen",
AppID: 1234,
InstallationID: 5678,
}
s.NoError(installationWithInstallationAndAppID.Upsert(s.ctx))
}
func (s *installationSuite) TestGetInstallationID() {
installation := GitHubAppInstallation{
Owner: "evergreen-ci",
Repo: "evergreen",
AppID: 1234,
InstallationID: 5678,
}
s.NoError(installation.Upsert(s.ctx))
authFields := &GithubAppAuth{
AppID: 1234,
}
id, err := getInstallationID(s.ctx, authFields, "evergreen-ci", "evergreen")
s.NoError(err)
s.Equal(installation.InstallationID, id)
_, err = getInstallationID(s.ctx, authFields, "evergreen-ci", "")
s.Error(err)
_, err = getInstallationID(s.ctx, authFields, "", "evergreen")
s.Error(err)
_, err = getInstallationID(s.ctx, authFields, "", "")
s.Error(err)
}