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

Function TestServer_Purge

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

Source from the content-addressed store, hash-verified

154}
155
156func TestServer_Purge(t *testing.T) {
157 t.Parallel()
158
159 ctx := context.Background()
160 srv := new(smtpmock.Server)
161 err := srv.Start(ctx, smtpmock.Config{
162 HostAddress: "127.0.0.1",
163 SMTPPort: 0,
164 APIPort: 0,
165 Logger: slogtest.Make(t, nil),
166 })
167 require.NoError(t, err)
168 defer srv.Stop()
169
170 err = sendTestEmail(srv.SMTPAddress(), "test-user@coder.com", "Test", "Body")
171 require.NoError(t, err)
172
173 require.Eventually(t, func() bool {
174 return srv.MessageCount() == 1
175 }, testutil.WaitShort, testutil.IntervalMedium)
176
177 url := fmt.Sprintf("%s/purge", srv.APIAddress())
178 req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil)
179 require.NoError(t, err)
180
181 resp, err := http.DefaultClient.Do(req)
182 require.NoError(t, err)
183 defer resp.Body.Close()
184 require.Equal(t, http.StatusOK, resp.StatusCode)
185
186 require.Equal(t, 0, srv.MessageCount())
187}
188
189func sendTestEmail(smtpAddr, to, subject, body string) error {
190 from := "noreply@coder.com"

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected