// Copyright 2024 Matthew Rich . All rights reserved. package containerlog import ( "github.com/stretchr/testify/assert" "testing" "bytes" ) func TestLogHeader(t *testing.T) { for _, v := range []struct{ expected error; value []byte } { { expected: nil, value: StreamStdout.Log("test message") }, { expected: nil, value: StreamStderr.Log("test error") }, { expected: ErrInvalidStreamType, value: StreamType(0x3).Log("fail") }, { expected: ErrInvalidStreamType, value: StreamType(0x4).Log("fail") }, } { var buf bytes.Buffer _, e := buf.Write(v.value) assert.Nil(t, e) logType, logSize, err := Header(&buf) assert.ErrorIs(t, err, v.expected) assert.ErrorIs(t, logType.Validate(), v.expected) if err == nil { assert.Equal(t, uint64(len(v.value) - 8), logSize) } } }