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

Function TestAPI_Events_CRUD

internal/server/http/api_test.go:104–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestAPI_Events_CRUD(t *testing.T) {
105 mux, store := setupAPI(t)
106 ctx := context.Background()
107
108 // Store an event
109 ev := event.Event{
110 UUID: "test-uuid-1",
111 Type: "sentry",
112 Payload: json.RawMessage(`{"message":"error"}`),
113 Timestamp: 1700000000.0,
114 Project: "default",
115 }
116 store.Store(ctx, ev)
117
118 // GET /api/events
119 t.Run("list events", func(t *testing.T) {
120 r := httptest.NewRequest("GET", "/api/events", nil)
121 w := httptest.NewRecorder()
122 mux.ServeHTTP(w, r)
123
124 var resp map[string]any
125 json.NewDecoder(w.Body).Decode(&resp)
126 data := resp["data"].([]any)
127 if len(data) != 1 {
128 t.Errorf("len = %d, want 1", len(data))
129 }
130 })
131
132 // GET /api/events?type=sentry
133 t.Run("filter by type", func(t *testing.T) {
134 r := httptest.NewRequest("GET", "/api/events?type=ray", nil)
135 w := httptest.NewRecorder()
136 mux.ServeHTTP(w, r)
137
138 var resp map[string]any
139 json.NewDecoder(w.Body).Decode(&resp)
140 data := resp["data"].([]any)
141 if len(data) != 0 {
142 t.Errorf("len = %d, want 0", len(data))
143 }
144 })
145
146 // GET /api/event/{uuid}
147 t.Run("get single event", func(t *testing.T) {
148 r := httptest.NewRequest("GET", "/api/event/test-uuid-1", nil)
149 w := httptest.NewRecorder()
150 mux.ServeHTTP(w, r)
151
152 if w.Code != 200 {
153 t.Fatalf("status = %d", w.Code)
154 }
155 var resp map[string]any
156 json.NewDecoder(w.Body).Decode(&resp)
157 if resp["uuid"] != "test-uuid-1" {
158 t.Errorf("uuid = %v", resp["uuid"])
159 }
160 })
161

Callers

nothing calls this directly

Calls 5

setupAPIFunction · 0.85
ServeHTTPMethod · 0.80
StoreMethod · 0.65
FindByUUIDMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected