github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/logger/journald/internal/export/export_test.go (about)

     1  package export_test
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/daemon/logger/journald/internal/export"
     8  	"gotest.tools/v3/assert"
     9  	"gotest.tools/v3/golden"
    10  )
    11  
    12  func TestExportSerialization(t *testing.T) {
    13  	must := func(err error) { t.Helper(); assert.NilError(t, err) }
    14  	var buf bytes.Buffer
    15  	must(export.WriteField(&buf, "_TRANSPORT", "journal"))
    16  	must(export.WriteField(&buf, "MESSAGE", "this is a single-line message.\tšŸš€"))
    17  	must(export.WriteField(&buf, "EMPTY_VALUE", ""))
    18  	must(export.WriteField(&buf, "NEWLINE", "\n"))
    19  	must(export.WriteEndOfEntry(&buf))
    20  
    21  	must(export.WriteField(&buf, "MESSAGE", "this is a\nmulti line\nmessage"))
    22  	must(export.WriteField(&buf, "INVALID_UTF8", "a\x80b"))
    23  	must(export.WriteField(&buf, "BINDATA", "\x00\x01\x02\x03"))
    24  	must(export.WriteEndOfEntry(&buf))
    25  
    26  	golden.Assert(t, buf.String(), "export-serialization.golden")
    27  }