(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 |
| 22 | Header1: Value1 |
| 23 | InvalidHeaderLine will be dropped |
| 24 | Header2: Value2 |
| 25 | |
| 26 | This 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 |
| 39 | Header1: Value1 |
| 40 | InvalidHeaderLine will be dropped |
| 41 | Header2: Value2 |
| 42 | |
| 43 | This 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") |
nothing calls this directly
no test coverage detected