Skip to content

Commit

Permalink
Add unit test, find and fix bugs in org detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Bodner committed May 11, 2016
1 parent aa3adad commit 4dfa5db
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions approval/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func Org(config *model.Config, maintainer *model.Maintainer, issue *model.Issue,
//value is name of person in the org
for _, name := range v.People {
if name == issue.Author {
authorOrg = name
authorOrg = k
}
m, ok := orgMap[name]
if !ok {
m := map[string]bool{}
m = map[string]bool{}
orgMap[name] = m
}
m[k] = true
Expand Down
80 changes: 80 additions & 0 deletions approval/org/org_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org

import (
"testing"
"github.com/lgtmco/lgtm/model"
)

var maintainerToml = `
[people]
[people.bob]
login = "bob"
[people.fred]
login = "fred"
[people.jon]
login = "jon"
[people.ralph]
login = "ralph"
[people.george]
login = "george"
[org]
[org.cap]
people = [
"bob",
"fred",
"jon"
]
[org.iron]
people = [
"ralph",
"george"
]
`

func TestOrg(t *testing.T) {
config := &model.Config {
Pattern: `(?i)LGTM\s*(\S*)`,
SelfApprovalOff: true,
}
m, err := model.ParseMaintainerStr(maintainerToml)
if err != nil {
t.Fatal(err)
}
issue := &model.Issue{
Author: "jon",
}
comments := []*model.Comment {
{
Body: "lgtm",
Author: "bob",
},
{
Body: "lgtm",
Author: "qwerty",
},
{
Body: "not an approval",
Author: "ralph",
},
{
Body: "lgtm",
Author: "george",
},
{
Body: "lgtm",
Author: "ralph",
},
}
people := []string{}
Org(config, m, issue, comments, func(m *model.Maintainer, c *model.Comment) {
people = append(people, c.Author)
})
if len(people) != 1 {
t.Errorf("Expected one person, had %d", len(people))
}
if people[0] != "george" {
t.Errorf("Expected george, had %s", people[0])
}
}

0 comments on commit 4dfa5db

Please sign in to comment.