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

Function TestLogLineCopy

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

Source from the content-addressed store, hash-verified

675}
676
677func TestLogLineCopy(t *testing.T) {
678 t.Run("nil", func(t *testing.T) {
679 ll := LogLine{FieldSeparator: ','}
680 cpy := ll.Copy()
681 if got := cpy.ToText(nil); got != nil {
682 t.Errorf("cpy.ToText() = %q, want nil", got)
683 }
684 })
685 t.Run("parse", func(t *testing.T) {
686 want := bytes.Repeat([]byte("some,random,fields,,,,"), 100)
687 ll := LogLine{FieldSeparator: ','}
688 ll.Parse(want, nil)
689 cpy := ll.Copy()
690 got := cpy.ToText(nil)
691 if !bytes.Equal(got, want) {
692 t.Errorf("cpy.ToText() = %q\n want nil", got)
693 }
694 })
695 t.Run("set", func(t *testing.T) {
696 want := []byte("value,value,,value")
697 ll := LogLine{FieldSeparator: ','}
698 ll.Set(0, []byte("value"))
699 ll.Set(1, []byte("value"))
700 ll.Set(3, []byte("value"))
701 ll.Set(LogLineNumFields, []byte("custom0"))
702 cpy := ll.Copy()
703 got := cpy.ToText(nil)
704 if !bytes.Equal(got, want) {
705 t.Errorf("cpy.ToText() = %q\n want %q", got, want)
706 }
707 got = cpy.Get(LogLineNumFields)
708 if !bytes.Equal(got, []byte("custom0")) {
709 t.Errorf("cpy.Get(LogLineNumFields) = %q\n want %q", got, want)
710 }
711 })
712 t.Run("parse and set", func(t *testing.T) {
713 text := bytes.Repeat([]byte("some,random,fields,,,,"), 100)
714 want := make([]byte, 0)
715 want = append(want, []byte("value")...)
716 want = append(want, text[4:]...)
717 ll := LogLine{FieldSeparator: ','}
718 ll.Parse(want, nil)
719 ll.Set(0, []byte("value"))
720 ll.Set(LogLineNumFields+10, []byte("custom10"))
721 cpy := ll.Copy()
722 got := cpy.ToText(nil)
723 if !bytes.Equal(got, want) {
724 t.Errorf("cpy.ToText() = %q\nwant %q", got, want)
725 }
726 got = cpy.Get(LogLineNumFields + 10)
727 if !bytes.Equal(got, []byte("custom10")) {
728 t.Errorf("cpy.Get(LogLineNumFields) = %q\n want %q", got, want)
729 }
730 })
731}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected