Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43165 from thaJeztah/20.10_backport_logs_fixes
[20.10 backport] daemon/logger: read the length header correctly
- Loading branch information
Showing
6 changed files
with
375 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package local | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/docker/docker/daemon/logger" | ||
"github.com/pkg/errors" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestDecode(t *testing.T) { | ||
marshal := makeMarshaller() | ||
|
||
buf, err := marshal(&logger.Message{Line: []byte("hello")}) | ||
assert.NilError(t, err) | ||
|
||
for i := 0; i < len(buf); i++ { | ||
testDecode(t, buf, i) | ||
} | ||
} | ||
|
||
func testDecode(t *testing.T, buf []byte, split int) { | ||
fw, err := ioutil.TempFile("", t.Name()) | ||
assert.NilError(t, err) | ||
defer os.Remove(fw.Name()) | ||
|
||
fr, err := os.Open(fw.Name()) | ||
assert.NilError(t, err) | ||
|
||
d := &decoder{rdr: fr} | ||
|
||
if split > 0 { | ||
_, err = fw.Write(buf[0:split]) | ||
assert.NilError(t, err) | ||
|
||
_, err = d.Decode() | ||
assert.Assert(t, errors.Is(err, io.EOF)) | ||
|
||
_, err = fw.Write(buf[split:]) | ||
assert.NilError(t, err) | ||
} else { | ||
_, err = fw.Write(buf) | ||
assert.NilError(t, err) | ||
} | ||
|
||
message, err := d.Decode() | ||
assert.NilError(t, err) | ||
assert.Equal(t, "hello\n", string(message.Line)) | ||
} |
Oops, something went wrong.