Skip to content

Commit

Permalink
add happy path test
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Wiesinger <[email protected]>
  • Loading branch information
mowies committed Jan 8, 2025
1 parent 3adad48 commit 6d72e4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions githubgen/codeowners.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ func (cg *codeownersGenerator) verifyCodeOwnerOrgMembership(allowlistData []byte
var missingCodeowners []string
var duplicateCodeowners []string

members, err := cg.getGithubMembers()
members, err := cg.GetGithubMembers()
if err != nil {
return err
}

Check warning on line 117 in githubgen/codeowners.go

View check run for this annotation

Codecov / codecov/patch

githubgen/codeowners.go#L116-L117

Added lines #L116 - L117 were not covered by tests

// sort codeowners
for _, codeowner := range data.Codeowners {
_, present := members[codeowner]
_, ownerPresentInMembers := members[codeowner]

if !present {
_, allowed := allowlist[codeowner]
if !ownerPresentInMembers {
_, ownerInAllowlist := allowlist[codeowner]
delete(unusedAllowlist, codeowner)
allowed = allowed || strings.HasPrefix(codeowner, "open-telemetry/")
if !allowed {
ownerInAllowlist = ownerInAllowlist || strings.HasPrefix(codeowner, "open-telemetry/")
if !ownerInAllowlist {
missingCodeowners = append(missingCodeowners, codeowner)
}
} else if _, exists := allowlist[codeowner]; exists {
Expand Down Expand Up @@ -152,7 +152,7 @@ func (cg *codeownersGenerator) verifyCodeOwnerOrgMembership(allowlistData []byte
return err
}

func (cg *codeownersGenerator) getGithubMembers() (map[string]struct{}, error) {
func (cg *codeownersGenerator) GetGithubMembers() (map[string]struct{}, error) {
if cg.skipGithub {
// don't try to get organization members if no token is expected
return map[string]struct{}{}, nil
Expand Down
27 changes: 18 additions & 9 deletions githubgen/codeowners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@ import (
)

func Test_codeownersGenerator_verifyCodeOwnerOrgMembership(t *testing.T) {
type fields struct {
skipGithub bool
}
type args struct {
allowlistData []byte
data datatype.GithubData
}
tests := []struct {
name string
fields fields
args args
wantErr bool
name string
skipGithub bool
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "happy path",
skipGithub: true,
args: args{
allowlistData: []byte(""),
data: datatype.GithubData{
Codeowners: []string{
"user1", "user2", "user3",
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cg := &codeownersGenerator{
skipGithub: tt.fields.skipGithub,
skipGithub: tt.skipGithub,
}
if err := cg.verifyCodeOwnerOrgMembership(tt.args.allowlistData, tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("verifyCodeOwnerOrgMembership() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit 6d72e4c

Please sign in to comment.