Skip to content

Commit 0575b02

Browse files
committed
pkg/repo: improve proposal validation test coverage
1 parent 6c41176 commit 0575b02

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

pkg/repo/repo_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,34 @@ func TestMain(m *testing.M) {
6666

6767
func TestProposalValidate(t *testing.T) {
6868
testcases := []struct {
69-
name string
70-
file string
71-
expectErrors bool
69+
name string
70+
file string
71+
errs []error
7272
}{
7373
{
74-
name: "valid KEP passes validate",
75-
file: "testdata/valid-kep.yaml",
76-
expectErrors: false,
74+
name: "valid KEP: all fields",
75+
file: "testdata/valid-kep-full.yaml",
76+
errs: nil,
7777
},
7878
{
79-
name: "invalid KEP fails validate for owning-sig",
80-
file: "testdata/invalid-kep.yaml",
81-
expectErrors: true,
79+
name: "invalid KEP: owning-sig does not exist",
80+
file: "testdata/invalid-owning-sig.yaml",
81+
errs: []error{
82+
fmt.Errorf("invalid owning-sig: not-a-sig"),
83+
},
84+
},
85+
{
86+
name: "invalid KEP: prr-approver does not exist",
87+
file: "testdata/invalid-prr-approver.yaml",
88+
errs: []error{
89+
fmt.Errorf("invalid prr-approver: not-a-prr-approver"),
90+
},
8291
},
8392
}
8493

8594
parser := api.KEPHandler{}
86-
parser.Groups = []string{"sig-api-machinery"}
95+
parser.Groups = []string{"sig-api-machinery", "sig-architecture", "sig-auth"}
96+
parser.PRRApprovers = []string{"@wojtek-t"}
8797

8898
for _, tc := range testcases {
8999
t.Run(tc.name, func(t *testing.T) {
@@ -95,11 +105,7 @@ func TestProposalValidate(t *testing.T) {
95105
require.NoError(t, err)
96106

97107
errs := parser.Validate(&p)
98-
if tc.expectErrors {
99-
require.NotEmpty(t, errs)
100-
}
101-
102-
require.NoError(t, err)
108+
require.ElementsMatch(t, tc.errs, errs)
103109
})
104110
}
105111
}

pkg/repo/testdata/invalid-kep.yaml renamed to pkg/repo/testdata/invalid-owning-sig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kep-number: 1687
33
authors:
44
- "@rjbez17"
55
- "@adrianludwin"
6-
owning-sig: sig-awesome
6+
owning-sig: not-a-sig
77
participating-sigs:
88
- sig-auth
99
reviewers:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
title: Hierarchical Namespace Controller As A Subproject
2+
kep-number: 1687
3+
authors:
4+
- "@rjbez17"
5+
- "@adrianludwin"
6+
owning-sig: sig-architecture
7+
participating-sigs:
8+
- sig-auth
9+
reviewers:
10+
- "TBD"
11+
approvers:
12+
- "@mikedanese"
13+
- "@deads2k"
14+
- "@liggitt"
15+
prr-approvers:
16+
- not-a-prr-approver
17+
creation-date: 2020-04-14
18+
last-updated: 2020-04-15
19+
stage: "alpha"
20+
status: provisional

pkg/repo/write_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestWriteKep(t *testing.T) {
4444
}{
4545
{
4646
name: "simple KEP",
47-
kepFile: "testdata/valid-kep.yaml",
47+
kepFile: "testdata/valid-kep-full.yaml",
4848
repoPath: "enhancements",
4949
kepName: "1010-test",
5050
sig: "sig-auth",
@@ -53,15 +53,15 @@ func TestWriteKep(t *testing.T) {
5353
},
5454
{
5555
name: "missing KEP name",
56-
kepFile: "testdata/valid-kep.yaml",
56+
kepFile: "testdata/valid-kep-full.yaml",
5757
repoPath: "enhancements",
5858
sig: "sig-auth",
5959
expectedPath: filepath.Join("enhancements", "keps", "sig-auth", "1010-test"),
6060
expectError: true,
6161
},
6262
{
6363
name: "missing owning SIG",
64-
kepFile: "testdata/valid-kep.yaml",
64+
kepFile: "testdata/valid-kep-full.yaml",
6565
repoPath: "enhancements",
6666
kepName: "1010-test",
6767
expectedPath: filepath.Join("enhancements", "keps", "sig-auth", "1010-test"),

0 commit comments

Comments
 (0)