| 223 | } |
| 224 | |
| 225 | func TestLogLineToText(t *testing.T) { |
| 226 | t.Run("default comma separator", func(t *testing.T) { |
| 227 | ll := LogLine{FieldSeparator: ','} |
| 228 | ll.Set(0, []byte("value1")) |
| 229 | ll.Set(1, []byte("value2")) |
| 230 | ll.Set(3, []byte("value4")) |
| 231 | text := ll.ToText(nil) |
| 232 | exp := []byte("value1,value2,,value4") |
| 233 | if !bytes.Equal(text, exp) { |
| 234 | t.Errorf("got: %s want: %s", text, exp) |
| 235 | } |
| 236 | }) |
| 237 | |
| 238 | t.Run("custom dot separator", func(t *testing.T) { |
| 239 | ll := LogLine{FieldSeparator: '.'} |
| 240 | ll.Set(0, []byte("value1")) |
| 241 | ll.Set(1, []byte("value2")) |
| 242 | ll.Set(3, []byte("value4")) |
| 243 | text := ll.ToText(nil) |
| 244 | exp := []byte("value1.value2..value4") |
| 245 | if !bytes.Equal(text, exp) { |
| 246 | t.Errorf("got: %s want: %s", text, exp) |
| 247 | } |
| 248 | }) |
| 249 | |
| 250 | t.Run("empty logline", func(t *testing.T) { |
| 251 | ll := LogLine{FieldSeparator: ','} |
| 252 | got := ll.ToText(nil) |
| 253 | if !bytes.Equal(got, []byte("")) { |
| 254 | t.Errorf("got: %s want: ''", got) |
| 255 | } |
| 256 | }) |
| 257 | |
| 258 | t.Run("set", func(t *testing.T) { |
| 259 | want := []byte(",,value2") |
| 260 | |
| 261 | ll := LogLine{FieldSeparator: ','} |
| 262 | ll.Set(2, []byte("value2")) |
| 263 | got := ll.ToText(nil) |
| 264 | if !bytes.Equal(got, want) { |
| 265 | t.Errorf("got: %s want: %s", got, want) |
| 266 | } |
| 267 | }) |
| 268 | |
| 269 | t.Run("parse", func(t *testing.T) { |
| 270 | want := []byte("value,value,value") |
| 271 | |
| 272 | ll := LogLine{FieldSeparator: ','} |
| 273 | ll.Parse(want, nil) |
| 274 | got := ll.ToText(nil) |
| 275 | if !bytes.Equal(got, want) { |
| 276 | t.Errorf("got: %s want: %s", got, want) |
| 277 | } |
| 278 | }) |
| 279 | |
| 280 | t.Run("parse with buffer", func(t *testing.T) { |
| 281 | want := []byte("value,value,value") |
| 282 | |