|
| 1 | +package syslog |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestExtractMessage(t *testing.T) { |
| 6 | + tests := []struct { |
| 7 | + name string |
| 8 | + input string |
| 9 | + expected string |
| 10 | + }{ |
| 11 | + { |
| 12 | + name: "info prefix", |
| 13 | + input: "[INFO] some message", |
| 14 | + expected: "some message", |
| 15 | + }, |
| 16 | + { |
| 17 | + name: "debug prefix", |
| 18 | + input: "[DEBUG] debug output", |
| 19 | + expected: "debug output", |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "warn prefix", |
| 23 | + input: "[WARN] something went wrong", |
| 24 | + expected: "something went wrong", |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "error prefix", |
| 28 | + input: "[ERROR] fatal error occurred", |
| 29 | + expected: "fatal error occurred", |
| 30 | + }, |
| 31 | + { |
| 32 | + name: "message with brackets in content", |
| 33 | + input: "[INFO] result [ok]", |
| 34 | + expected: "result [ok]", |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "no bracket in line", |
| 38 | + input: "xno bracket here", |
| 39 | + expected: "no bracket here", |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + for _, tt := range tests { |
| 44 | + t.Run(tt.name, func(t *testing.T) { |
| 45 | + got := extractMessage(tt.input) |
| 46 | + if got != tt.expected { |
| 47 | + t.Errorf("extractMessage(%q) = %q, want %q", tt.input, got, tt.expected) |
| 48 | + } |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
0 commit comments