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>
diff --git a/maintner/github.go b/maintner/github.go
index ca2b1e0..128858d 100644
--- a/maintner/github.go
+++ b/maintner/github.go
@@ -62,6 +62,9 @@
}
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 @@
// 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)
diff --git a/maintner/maintner_test.go b/maintner/maintner_test.go
index be05cef..b3d587f 100644
--- a/maintner/maintner_test.go
+++ b/maintner/maintner_test.go
@@ -112,6 +112,25 @@
})
}
+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),