maintner: fix un-initialized github panic

Previously processGithubIssueMutation called initGithub, but
processGithubMutation did not, so if your on-disk mutation file had
a GithubMutation before a GithubIssueMutation, c.github would be nil
and Initialize() would panic.

Call initGithub from processGithubMutation and add a test to protect
against regressions.

Change-Id: Ie706fa04cb8ea87c2e0259dbee024c0005f0523f
Reviewed-on: https://go-review.googlesource.com/41298
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Kevin Burke 2017-04-20 22:46:02 -07:00 коммит произвёл Brad Fitzpatrick
Родитель a98587f60c
Коммит 022bf90f00
2 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -62,6 +62,9 @@ func (g *GitHub) Repo(owner, repo string) *GitHubRepo {
}
func (g *GitHub) getOrCreateRepo(owner, repo string) *GitHubRepo {
if g == nil {
panic("cannot call methods on nil GitHub")
}
id := GithubRepoID{owner, repo}
if !id.valid() {
return nil
@ -956,6 +959,10 @@ func (r *GitHubRepo) missingIssues() []int32 {
// processGithubMutation updates the corpus with the information in m.
func (c *Corpus) processGithubMutation(m *maintpb.GithubMutation) {
if c == nil {
panic("nil corpus")
}
c.initGithub()
gr := c.github.getOrCreateRepo(m.Owner, m.Repo)
if gr == nil {
log.Printf("bogus Owner/Repo %q/%q in mutation: %v", m.Owner, m.Repo, m)

Просмотреть файл

@ -112,6 +112,25 @@ func TestProcessMutation_Github_NewIssue(t *testing.T) {
})
}
func TestProcessMutation_Github(t *testing.T) {
c := NewCorpus(&dummyMutationLogger{}, "")
github := &GitHub{c: c}
c.github = github
github.repos = map[GithubRepoID]*GitHubRepo{
GithubRepoID{"golang", "go"}: &GitHubRepo{
github: github,
id: GithubRepoID{"golang", "go"},
issues: make(map[int32]*GitHubIssue),
},
}
mutationTest{want: c}.test(t, &maintpb.Mutation{
Github: &maintpb.GithubMutation{
Owner: "golang",
Repo: "go",
},
})
}
func TestNewMutationsFromIssue(t *testing.T) {
gh := &github.Issue{
Number: github.Int(5),