MCPcopy Create free account
hub / github.com/buggregator/server / TestSMTPAPI_Stats

Function TestSMTPAPI_Stats

modules/smtp/api_test.go:256–290  ·  view source on GitHub ↗

TestSMTPAPI_Stats verifies the stats endpoint.

(t *testing.T)

Source from the content-addressed store, hash-verified

254
255// TestSMTPAPI_Stats verifies the stats endpoint.
256func TestSMTPAPI_Stats(t *testing.T) {
257 mux, store, _ := setupAPITest(t)
258
259 t.Run("empty", func(t *testing.T) {
260 r := httptest.NewRequest("GET", "/api/smtp/stats", nil)
261 w := httptest.NewRecorder()
262 mux.ServeHTTP(w, r)
263
264 var resp map[string]any
265 json.NewDecoder(w.Body).Decode(&resp)
266 if resp["count"].(float64) != 0 {
267 t.Errorf("count = %v, want 0", resp["count"])
268 }
269 if resp["last_received_at"] != nil {
270 t.Errorf("last_received_at should be nil for empty store, got %v", resp["last_received_at"])
271 }
272 })
273
274 storeSMTPEvent(t, store, "st-uuid1", ParsedEmail{Subject: "Test"}, 1000.0, "default")
275
276 t.Run("one message", func(t *testing.T) {
277 r := httptest.NewRequest("GET", "/api/smtp/stats", nil)
278 w := httptest.NewRecorder()
279 mux.ServeHTTP(w, r)
280
281 var resp map[string]any
282 json.NewDecoder(w.Body).Decode(&resp)
283 if resp["count"].(float64) != 1 {
284 t.Errorf("count = %v, want 1", resp["count"])
285 }
286 if resp["last_received_at"] == nil {
287 t.Error("last_received_at should not be nil")
288 }
289 })
290}
291
292// TestSMTPAPI_Raw verifies the raw RFC822 endpoint.
293func TestSMTPAPI_Raw(t *testing.T) {

Callers

nothing calls this directly

Calls 4

setupAPITestFunction · 0.85
storeSMTPEventFunction · 0.85
ServeHTTPMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected