MCPcopy Create free account
hub / github.com/AdRoll/baker / TestLogLineCustomFields

Function TestLogLineCustomFields

logline_test.go:503–575  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

501}
502
503func TestLogLineCustomFields(t *testing.T) {
504 t.Run("parse error to many fields", func(t *testing.T) {
505 values := make([]string, 0, LogLineNumFields)
506 // Create a buffer with 3001 fields and 3000 separators.
507 for i := 0; i < int(LogLineNumFields)+1; i++ {
508 values = append(values, "value")
509 }
510 want := []byte(strings.Join(values, ","))
511
512 ll := LogLine{FieldSeparator: ','}
513 err := ll.Parse(want, nil)
514 if err != errLogLineTooManyFields {
515 t.Errorf("ll.Parse()= %q, want error %q", err, errLogLineTooManyFields)
516 }
517 })
518
519 t.Run("set/get custom fields", func(t *testing.T) {
520 ll := LogLine{FieldSeparator: ','}
521
522 want := []byte("custom1")
523 idx := LogLineNumFields
524 ll.Set(idx, want)
525 got := ll.Get(idx)
526 if !bytes.Equal(got, want) {
527 t.Errorf("ll.Get(%d)= %q, want %q", idx, got, want)
528
529 }
530
531 want = []byte("customN")
532 idx = LogLineNumFields + NumFieldsBaker - 1
533 ll.Set(idx, want)
534 got = ll.Get(idx)
535 if !bytes.Equal(got, want) {
536 t.Errorf("ll.Get(%d)= %q, want %q", idx, got, want)
537 }
538
539 // Custom fields should not be serialized.
540 got = ll.ToText(nil)
541 if !bytes.Equal(got, []byte{}) {
542 t.Errorf("ll.ToText()= %q, want ''", got)
543 }
544 })
545
546 t.Run("zerovalue + copy custom fields", func(t *testing.T) {
547 ll := LogLine{FieldSeparator: ','}
548 for i := FieldIndex(LogLineNumFields); i < FieldIndex(LogLineNumFields+NumFieldsBaker); i++ {
549 ll.Set(i, []byte("custom"+strconv.Itoa(int(i))))
550 }
551
552 cpy := ll.Copy()
553 for i := FieldIndex(LogLineNumFields); i < FieldIndex(LogLineNumFields+NumFieldsBaker); i++ {
554 got, want := cpy.Get(i), []byte("custom"+strconv.Itoa(int(i)))
555 if !bytes.Equal(got, want) {
556 t.Fatalf("ll.Get(%d) = %q, want %q", i, got, want)
557 }
558 }
559 })
560 t.Run("parse + copy custom fields", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

ParseMethod · 0.95
SetMethod · 0.95
GetMethod · 0.95
ToTextMethod · 0.95
CopyMethod · 0.95
FieldIndexTypeAlias · 0.85
RunMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected