(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func TestSendSystemAlertToAllSuperusers(t *testing.T) { |
| 64 | t.Parallel() |
| 65 | |
| 66 | testDataDir, err := os.MkdirTemp("", "sendSystemAlertToAllSuperusers_pb_data") |
| 67 | if err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | defer os.RemoveAll(testDataDir) |
| 71 | |
| 72 | testApp := NewBaseApp(BaseAppConfig{ |
| 73 | DataDir: testDataDir, |
| 74 | }) |
| 75 | defer testApp.ResetBootstrapState() |
| 76 | |
| 77 | if err := testApp.Bootstrap(); err != nil { |
| 78 | t.Fatal(err) |
| 79 | } |
| 80 | |
| 81 | if err := createTestSuperusers(testApp, 3); err != nil { |
| 82 | t.Fatal(err) |
| 83 | } |
| 84 | |
| 85 | var sendCalls int |
| 86 | testApp.OnMailerSend().BindFunc(func(e *MailerEvent) error { |
| 87 | sendCalls++ |
| 88 | |
| 89 | if !strings.Contains(e.Message.Subject, "test_subject") { |
| 90 | t.Fatalf("Missing %q in Message.Subject:\n%s", "test_subject", e.Message.Subject) |
| 91 | } |
| 92 | |
| 93 | if !strings.Contains(e.Message.HTML, "test_details") { |
| 94 | t.Fatalf("Missing %q in Message.HTML:\n%s", "test_details", e.Message.HTML) |
| 95 | } |
| 96 | |
| 97 | return nil |
| 98 | }) |
| 99 | |
| 100 | sendSystemAlertToAllSuperusers(testApp, "test_subject", "test_details") |
| 101 | |
| 102 | if sendCalls != 3 { |
| 103 | t.Fatalf("Expected 3 mail send calls, got %d", sendCalls) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | func createTestSuperusers(app App, total int) error { |
| 108 | superusersCollection, err := app.FindCollectionByNameOrId(CollectionNameSuperusers) |
nothing calls this directly
no test coverage detected
searching dependent graphs…