MCPcopy Create free account
hub / github.com/coder/coder / TestServer_SendAndReceiveEmail

Function TestServer_SendAndReceiveEmail

scaletest/smtpmock/server_test.go:40–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestServer_SendAndReceiveEmail(t *testing.T) {
41 t.Parallel()
42
43 ctx := context.Background()
44 srv := new(smtpmock.Server)
45 err := srv.Start(ctx, smtpmock.Config{
46 HostAddress: "127.0.0.1",
47 SMTPPort: 0,
48 APIPort: 0,
49 Logger: slogtest.Make(t, nil),
50 })
51 require.NoError(t, err)
52 defer srv.Stop()
53
54 err = sendTestEmail(srv.SMTPAddress(), "test@example.com", "Test Subject", "Test Body")
55 require.NoError(t, err)
56
57 require.Eventually(t, func() bool {
58 return srv.MessageCount() == 1
59 }, testutil.WaitShort, testutil.IntervalMedium)
60
61 url := fmt.Sprintf("%s/messages", srv.APIAddress())
62 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
63 require.NoError(t, err)
64
65 resp, err := http.DefaultClient.Do(req)
66 require.NoError(t, err)
67 defer resp.Body.Close()
68
69 require.Equal(t, http.StatusOK, resp.StatusCode)
70
71 var summaries []smtpmock.EmailSummary
72 err = json.NewDecoder(resp.Body).Decode(&summaries)
73 require.NoError(t, err)
74 require.Len(t, summaries, 1)
75 require.Equal(t, "Test Subject", summaries[0].Subject)
76}
77
78func TestServer_FilterByEmail(t *testing.T) {
79 t.Parallel()

Callers

nothing calls this directly

Calls 10

sendTestEmailFunction · 0.85
SMTPAddressMethod · 0.80
MessageCountMethod · 0.80
StartMethod · 0.65
StopMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
APIAddressMethod · 0.45
EqualMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected