| @@ -38,6 +38,49 @@ func (i *instance) runnerOnce(t *testing.T, key string) string { |
| 38 | 38 | return string(out) |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | // A failed build mails the repo owner with the log tail; green builds |
| 42 | // stay silent. |
| 43 | func TestBuildFailureMail(t *testing.T) { |
| 44 | smtp := startFakeSMTP(t) |
| 45 | inst := startInstanceWith(t, fmt.Sprintf( |
| 46 | "[mail]\nsmtp_host = %q\nfrom = \"noreply@gitbay.test\"\n", smtp.addr)) |
| 47 | inst.runner = buildRunner(t) |
| 48 | aliceKey := inst.newKey(t, "alice") |
| 49 | inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub", |
| 50 | "--email", "alice@example.test", "--verified") |
| 51 | runnerKey := inst.newKey(t, "ci") |
| 52 | inst.admin(t, "admin", "user", "create", "ci", "--key", runnerKey+".pub", "--admin") |
| 53 | |
| 54 | if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 { |
| 55 | t.Fatalf("repo create: %s", errOut) |
| 56 | } |
| 57 | work := t.TempDir() |
| 58 | env := inst.gitEnv(aliceKey) |
| 59 | mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w") |
| 60 | dir := filepath.Join(work, "w") |
| 61 | os.MkdirAll(filepath.Join(dir, ".gitbay"), 0o755) |
| 62 | os.WriteFile(filepath.Join(dir, ".gitbay", "ci.yml"), []byte( |
| 63 | "jobs:\n ok:\n steps:\n - echo fine\n broken:\n steps:\n - echo the dataset went stale && false\n"), 0o644) |
| 64 | mustGit(t, dir, env, "checkout", "-q", "-b", "main") |
| 65 | mustGit(t, dir, env, "add", ".") |
| 66 | mustGit(t, dir, env, "commit", "-q", "-m", "base") |
| 67 | mustGit(t, dir, env, "push", "-q", "origin", "main") |
| 68 | |
| 69 | inst.runnerOnce(t, runnerKey) // broken (sorts first) |
| 70 | inst.runnerOnce(t, runnerKey) // ok |
| 71 | mail := smtp.waitFor(t, "alice@example.test", "failed") |
| 72 | if !strings.Contains(mail, "broken") || !strings.Contains(mail, "the dataset went stale") || |
| 73 | !strings.Contains(mail, "/alice/app/builds/") { |
| 74 | t.Fatalf("failure mail missing detail:\n%s", mail) |
| 75 | } |
| 76 | // Only the failure mailed: no message mentions the green job. |
| 77 | for _, m := range smtp.mailTo("alice@example.test") { |
| 78 | if strings.Contains(m, "build") && strings.Contains(m, " ok ") && strings.Contains(m, "failed") == false { |
| 79 | t.Fatalf("green build mailed:\n%s", m) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 41 | 84 | func TestCI(t *testing.T) { |
| 42 | 85 | inst := startInstance(t) |
| 43 | 86 | inst.runner = buildRunner(t) |