Download this file
| 1 | package docs |
| 2 | |
| 3 | import ( |
| 4 | "log/slog" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // TestNoMailRefusesOutsideDevelopment is the third boot of CARLOS mail |
| 10 | // submission (cmd/docs mail_test.go has the other two): with neither |
| 11 | // channel, cmd/docs leaves Mailer nil, and that is a refusal anywhere |
| 12 | // but development, naming both ways to fix it. |
| 13 | func TestNoMailRefusesOutsideDevelopment(t *testing.T) { |
| 14 | logger := slog.New(slog.DiscardHandler) |
| 15 | _, _, err := buildMailer(Config{Env: "production"}, logger) |
| 16 | if err == nil { |
| 17 | t.Fatal("started with no mail in production") |
| 18 | } |
| 19 | for _, want := range []string{"CARLOS_MAIL=submit", "DOCS_SMTP_HOST"} { |
| 20 | if !strings.Contains(err.Error(), want) { |
| 21 | t.Errorf("refusal %q does not name %s", err, want) |
| 22 | } |
| 23 | } |
| 24 | if sender, _, err := buildMailer(Config{Env: "development"}, logger); err != nil || sender == nil { |
| 25 | t.Fatalf("development: sender %v, err %v", sender, err) |
| 26 | } |
| 27 | } |
| 28 | |