MCPcopy Index your code
hub / github.com/devaccuracy/ledgerforge / TestProcessWebhookWithReusedClient

Function TestProcessWebhookWithReusedClient

webhooks_test.go:208–266  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

206}
207
208func TestProcessWebhookWithReusedClient(t *testing.T) {
209 // Track that the same client instance is used
210 var clientUsed *http.Client
211 var clientMutex sync.Mutex
212
213 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
214 w.WriteHeader(http.StatusOK)
215 _, _ = w.Write([]byte(`{"status":"ok"}`))
216 }))
217 defer server.Close()
218
219 // Setup miniredis
220 mr, err := miniredis.Run()
221 if err != nil {
222 t.Fatalf("an error '%s' occurred when starting miniredis", err)
223 }
224 defer mr.Close()
225
226 cnf := &config.Configuration{
227 Redis: config.RedisConfig{
228 Dns: mr.Addr(),
229 },
230 Queue: config.QueueConfig{
231 WebhookQueue: "webhook_queue",
232 NumberOfQueues: 1,
233 },
234 Notification: config.Notification{
235 Webhook: config.WebhookConfig{
236 Url: server.URL,
237 },
238 },
239 }
240 config.ConfigStore.Store(cnf)
241
242 ledgerforge, err := NewLedgerForge(nil)
243 assert.NoError(t, err)
244 defer func() { _ = ledgerforge.Close() }()
245
246 // Store reference to the HTTP client
247 clientMutex.Lock()
248 clientUsed = ledgerforge.httpClient
249 clientMutex.Unlock()
250
251 // Create webhook payloads
252 webhook1 := NewWebhook{Event: "test.event1", Payload: map[string]string{"id": "1"}}
253 webhook2 := NewWebhook{Event: "test.event2", Payload: map[string]string{"id": "2"}}
254
255 // Process webhooks using the same client
256 err1 := processHTTP(webhook1, ledgerforge.httpClient)
257 err2 := processHTTP(webhook2, ledgerforge.httpClient)
258
259 assert.NoError(t, err1)
260 assert.NoError(t, err2)
261
262 // Verify the same client instance was used
263 clientMutex.Lock()
264 assert.Same(t, clientUsed, ledgerforge.httpClient, "Should use the same HTTP client instance")
265 clientMutex.Unlock()

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
NewLedgerForgeFunction · 0.85
processHTTPFunction · 0.85
CloseMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected