mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
c91e09bee2
Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
37 lines
820 B
Go
37 lines
820 B
Go
package loggerutils // import "github.com/docker/docker/daemon/logger/loggerutils"
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestHandleDecoderErr(t *testing.T) {
|
|
f, err := os.CreateTemp("", t.Name())
|
|
assert.NilError(t, err)
|
|
defer os.Remove(f.Name())
|
|
|
|
_, err = f.Write([]byte("hello"))
|
|
assert.NilError(t, err)
|
|
|
|
pos, err := f.Seek(0, io.SeekCurrent)
|
|
assert.NilError(t, err)
|
|
assert.Assert(t, pos != 0)
|
|
|
|
dec := &testDecoder{}
|
|
|
|
// Simulate "turncate" case, where the file was bigger before.
|
|
fl := &follow{file: f, dec: dec, oldSize: 100}
|
|
err = fl.handleDecodeErr(io.EOF)
|
|
assert.NilError(t, err)
|
|
|
|
// handleDecodeErr seeks to zero.
|
|
pos, err = f.Seek(0, io.SeekCurrent)
|
|
assert.NilError(t, err)
|
|
assert.Equal(t, int64(0), pos)
|
|
|
|
// Reset is called.
|
|
assert.Equal(t, 1, dec.resetCount)
|
|
}
|