MCPcopy
hub / github.com/kopia/kopia / TestJSONSender

Function TestJSONSender

notification/sender/jsonsender/jsonsender_test.go:16–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestJSONSender(t *testing.T) {
17 ctx := testlogging.Context(t)
18
19 var buf bytes.Buffer
20
21 p := jsonsender.NewJSONSender("NOTIFICATION:", &buf, notification.SeverityWarning)
22
23 m1 := &sender.Message{
24 Subject: "test subject 1",
25 Body: "test body 1",
26 Severity: notification.SeverityVerbose,
27 }
28 m2 := &sender.Message{
29 Subject: "test subject 2",
30 Body: "test body 2",
31 Severity: notification.SeverityWarning,
32 }
33 m3 := &sender.Message{
34 Subject: "test subject 3",
35 Body: "test body 3",
36 Severity: notification.SeverityError,
37 }
38
39 require.NoError(t, p.Send(ctx, m1)) // will be ignored
40 require.NoError(t, p.Send(ctx, m2))
41 require.NoError(t, p.Send(ctx, m3))
42
43 lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
44
45 require.Equal(t,
46 []string{
47 "NOTIFICATION:{\"subject\":\"test subject 2\",\"severity\":10,\"body\":\"test body 2\"}",
48 "NOTIFICATION:{\"subject\":\"test subject 3\",\"severity\":20,\"body\":\"test body 3\"}",
49 }, lines)
50}

Callers

nothing calls this directly

Calls 5

ContextFunction · 0.92
NewJSONSenderFunction · 0.92
EqualMethod · 0.80
SendMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected