-
Notifications
You must be signed in to change notification settings - Fork 57
/
github_test.go
141 lines (114 loc) · 4.17 KB
/
github_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
package governance_test
import (
"os"
"sort"
"testing"
"github.com/concourse/governance"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGitHub(t *testing.T) {
config, err := governance.LoadConfig(os.DirFS("."))
require.NoError(t, err)
desired := config.DesiredGitHubState()
actual, err := governance.LoadGitHubState("concourse")
require.NoError(t, err)
t.Run("members", func(t *testing.T) {
for _, member := range desired.Members {
actualMember, found := actual.Member(member.Login)
if assert.True(t, found, "%s should be a member of the organization, but is not", member.Login) {
assert.Equal(t, member.Role, actualMember.Role, "%s has wrong role", member.Login)
}
}
for _, member := range actual.Members {
_, found := desired.Member(member.Login)
assert.True(t, found, "%s should not be a member", member.Login)
}
})
t.Run("repos", func(t *testing.T) {
for _, d := range desired.Repos {
desiredRepo := d
t.Run(desiredRepo.Name, func(t *testing.T) {
actualRepo, found := actual.Repo(desiredRepo.Name)
require.True(t, found, "repo does not exist")
t.Run("has matching configuration", func(t *testing.T) {
require.Equal(t, desiredRepo.Description, actualRepo.Description, "description")
require.Equal(t, desiredRepo.IsPrivate, actualRepo.IsPrivate, "privacy")
require.ElementsMatch(t, desiredRepo.Topics, actualRepo.Topics, "topics")
require.Equal(t, desiredRepo.HomepageURL, actualRepo.HomepageURL, "homepage URL")
require.Equal(t, desiredRepo.HasIssues, actualRepo.HasIssues, "has issues")
require.Equal(t, desiredRepo.HasProjects, actualRepo.HasProjects, "has projects")
require.Equal(t, desiredRepo.HasWiki, actualRepo.HasWiki, "has wiki")
require.ElementsMatch(t, desiredRepo.DirectCollaborators, actualRepo.DirectCollaborators, "collaborators")
})
t.Run("has correct branch protection", func(t *testing.T) {
for _, rule := range desiredRepo.BranchProtectionRules {
sort.Strings(rule.RequiredStatusCheckContexts)
}
for _, rule := range actualRepo.BranchProtectionRules {
sort.Strings(rule.RequiredStatusCheckContexts)
}
require.ElementsMatch(t, desiredRepo.BranchProtectionRules, actualRepo.BranchProtectionRules, "branch protection")
})
t.Run("has correct deploy keys", func(t *testing.T) {
require.ElementsMatch(t, desiredRepo.DeployKeys, actualRepo.DeployKeys, "deploy keys")
})
t.Run("belongs to a team", func(t *testing.T) {
var belongs bool
for _, team := range desired.Teams {
for _, repo := range team.Repos {
if repo.Name == desiredRepo.Name {
belongs = true
}
}
}
require.True(t, belongs, "does not belong to any team")
})
})
}
for _, a := range actual.Repos {
actualRepo := a
_, found := desired.Repo(actualRepo.Name)
if found {
continue
}
t.Run(actualRepo.Name, func(t *testing.T) {
t.Error("repo is not in configuration")
})
}
})
t.Run("teams", func(t *testing.T) {
for _, d := range desired.Teams {
desiredTeam := d
t.Run(desiredTeam.Name, func(t *testing.T) {
actualTeam, found := actual.Team(desiredTeam.Name)
require.True(t, found, "team does not exist")
t.Run("members", func(t *testing.T) {
for _, member := range desiredTeam.Members {
actualMember, found := actualTeam.Member(member.Login)
if assert.True(t, found, "%s should be a member of the %s team, but is not", member.Login, desiredTeam.Name) {
assert.Equal(t, member.Role, actualMember.Role, "%s has wrong role", member.Login)
}
}
for _, member := range actualTeam.Members {
_, found := desiredTeam.Member(member.Login)
assert.True(t, found, "%s should not be a member of the %s team", member.Login, desiredTeam.Name)
}
})
t.Run("repos", func(t *testing.T) {
require.ElementsMatch(t, desiredTeam.Repos, actualTeam.Repos)
})
})
}
for _, a := range actual.Teams {
actualTeam := a
_, found := desired.Team(actualTeam.Name)
if found {
continue
}
t.Run(actualTeam.Name, func(t *testing.T) {
t.Error("team should not exist")
})
}
})
}