logtail: cap the buffer size in encodeText

This started as an attempt to placate GitHub's code scanner,
but it's also probably generally a good idea.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2022-01-13 14:02:46 -08:00
committed by Josh Bleecher Snyder
parent 5404a0557b
commit 9fe5ece833
2 changed files with 32 additions and 9 deletions

View File

@ -5,6 +5,7 @@
package logtail
import (
"bytes"
"context"
"encoding/json"
"io"
@ -323,3 +324,14 @@ func unmarshalOne(t *testing.T, body []byte) map[string]interface{} {
}
return entries[0]
}
func TestEncodeTextTruncation(t *testing.T) {
lg := &Logger{timeNow: time.Now, lowMem: true}
in := bytes.Repeat([]byte("a"), 300)
b := lg.encodeText(in, true)
got := string(b)
want := `{"text": "` + strings.Repeat("a", 255) + `…+45"}` + "\n"
if got != want {
t.Errorf("got:\n%qwant:\n%q\n", got, want)
}
}