(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 | } |
nothing calls this directly
no test coverage detected