MCPcopy
hub / github.com/kopia/kopia / remoteRepositoryNotificationTest

Function remoteRepositoryNotificationTest

internal/server/server_test.go:270–320  ·  view source on GitHub ↗

nolint:thelper

(t *testing.T, ctx context.Context, rep repo.Repository, rw repo.RepositoryWriter)

Source from the content-addressed store, hash-verified

268
269//nolint:thelper
270func remoteRepositoryNotificationTest(t *testing.T, ctx context.Context, rep repo.Repository, rw repo.RepositoryWriter) {
271 require.Implements(t, (*repo.RemoteNotifications)(nil), rep)
272
273 mux := http.NewServeMux()
274
275 var numRequestsReceived atomic.Int32
276
277 mux.HandleFunc("/some-path", func(w http.ResponseWriter, r *http.Request) {
278 numRequestsReceived.Add(1)
279 })
280
281 server := httptest.NewServer(mux)
282 defer server.Close()
283
284 require.NoError(t, notifyprofile.SaveProfile(ctx, rw, notifyprofile.Config{
285 ProfileName: "my-profile",
286 MethodConfig: sender.MethodConfig{
287 Type: "webhook",
288 Config: &webhook.Options{
289 Endpoint: server.URL + "/some-path",
290 Method: "POST",
291 },
292 },
293 }))
294 require.NoError(t, rw.Flush(ctx))
295
296 notification.Send(ctx, rep, notifytemplate.TestNotification, notifydata.EmptyEventData{}, notification.SeverityError, notifytemplate.DefaultOptions)
297 require.Equal(t, int32(1), numRequestsReceived.Load())
298
299 // another webhook which fails
300
301 require.NoError(t, notifyprofile.SaveProfile(ctx, rw, notifyprofile.Config{
302 ProfileName: "my-profile",
303 MethodConfig: sender.MethodConfig{
304 Type: "webhook",
305 Config: &webhook.Options{
306 Endpoint: server.URL + "/some-nonexistent-path",
307 Method: "POST",
308 },
309 },
310 }))
311
312 require.NoError(t, rw.Flush(ctx))
313
314 t0 := clock.Now()
315 t1 := clock.Now().Add(10 * time.Second)
316
317 notification.Send(ctx, rep, "generic-error",
318 notifydata.NewErrorInfo("op", "some error occurred", t0, t1, errors.New("some error")), notification.SeverityError, notifytemplate.DefaultOptions)
319 require.Equal(t, int32(1), numRequestsReceived.Load())
320}
321
322func mustWriteObject(ctx context.Context, t *testing.T, w repo.RepositoryWriter, data []byte) object.ID {
323 t.Helper()

Callers 1

TestServerFunction · 0.85

Calls 9

SaveProfileFunction · 0.92
SendFunction · 0.92
NowFunction · 0.92
NewErrorInfoFunction · 0.92
EqualMethod · 0.80
CloseMethod · 0.65
FlushMethod · 0.65
LoadMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected