MCPcopy
hub / github.com/kopia/kopia / TestParseMessage

Function TestParseMessage

notification/sender/notification_message_test.go:13–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestParseMessage(t *testing.T) {
14 testCases := []struct {
15 name string
16 input string
17 expected *sender.Message
18 }{
19 {
20 name: "ValidMessage",
21 input: `Subject: Test Subject
22Header1: Value1
23InvalidHeaderLine will be dropped
24Header2: Value2
25
26This is the body of the message.`,
27 expected: &sender.Message{
28 Subject: "Test Subject",
29 Headers: map[string]string{
30 "Header1": "Value1",
31 "Header2": "Value2",
32 },
33 Body: "This is the body of the message.",
34 },
35 },
36 {
37 name: "ValidMessage",
38 input: `Subject: Test Subject
39Header1: Value1
40InvalidHeaderLine will be dropped
41Header2: Value2
42
43This is the body of the message.`,
44 expected: &sender.Message{
45 Subject: "Test Subject",
46 Headers: map[string]string{
47 "Header1": "Value1",
48 "Header2": "Value2",
49 },
50 Body: "This is the body of the message.",
51 },
52 }, // Add more test cases here...
53 }
54
55 for _, tc := range testCases {
56 t.Run(tc.name, func(t *testing.T) {
57 reader := strings.NewReader(tc.input)
58 ctx := testlogging.Context(t)
59 actual, err := sender.ParseMessage(ctx, reader)
60
61 require.NoError(t, err)
62 require.Equal(t, tc.expected.Subject, actual.Subject, "ParseMessage() Subject mismatch")
63 require.Equal(t, tc.expected.Body, actual.Body, "ParseMessage() Body mismatch")
64 require.Equal(t, tc.expected.Headers, actual.Headers, "ParseMessage() Headers mismatch")
65
66 actualString := actual.ToString()
67 roundTrip, err := sender.ParseMessage(ctx, strings.NewReader(actualString))
68 require.NoError(t, err)
69
70 require.Equal(t, tc.expected, roundTrip, "ToString() did not roundtrip")

Callers

nothing calls this directly

Calls 5

ContextFunction · 0.92
ParseMessageFunction · 0.92
EqualMethod · 0.80
ToStringMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected