From 8ff289ea4f7c81eacf7a95373ec525f84c549d08 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Thu, 10 Dec 2020 18:15:43 +0300 Subject: [PATCH] Simplify OffsetWriter Signed-off-by: Evgeniy Kulikov --- api/layer/writer.go | 2 +- api/layer/writer_test.go | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/api/layer/writer.go b/api/layer/writer.go index 833a794e..2290e391 100644 --- a/api/layer/writer.go +++ b/api/layer/writer.go @@ -12,7 +12,7 @@ type offsetWriter struct { length int64 } -func newWriter(w io.Writer, offset, length int64) io.Writer { +func newWriter(w io.Writer, offset, length int64) *offsetWriter { return &offsetWriter{ Writer: w, offset: offset, diff --git a/api/layer/writer_test.go b/api/layer/writer_test.go index 1a242f64..762f1dd6 100644 --- a/api/layer/writer_test.go +++ b/api/layer/writer_test.go @@ -33,10 +33,8 @@ func TestOffsetWriter(t *testing.T) { require.NoError(t, err) } - wo := wt.(*offsetWriter) - - require.Equal(t, o, wo.skipped) - require.Equal(t, l, wo.written) + require.Equal(t, o, wt.skipped) + require.Equal(t, l, wt.written) require.Equal(t, b[o:o+l], w.Bytes()) }) @@ -51,10 +49,8 @@ func TestOffsetWriter(t *testing.T) { require.NoError(t, err) } - wo := wt.(*offsetWriter) - - require.Equal(t, o, wo.skipped) - require.Equal(t, l, wo.written) + require.Equal(t, o, wt.skipped) + require.Equal(t, l, wt.written) require.Equal(t, b[o:o+l], w.Bytes()) }) @@ -69,10 +65,8 @@ func TestOffsetWriter(t *testing.T) { require.NoError(t, err) } - wo := wt.(*offsetWriter) - - require.Equal(t, o, wo.skipped) - require.Equal(t, l, wo.written) + require.Equal(t, o, wt.skipped) + require.Equal(t, l, wt.written) require.Equal(t, b[o:o+l], w.Bytes()) }) @@ -87,10 +81,8 @@ func TestOffsetWriter(t *testing.T) { require.NoError(t, err) } - wo := wt.(*offsetWriter) - - require.Equal(t, o, wo.skipped) - require.Equal(t, s, wo.written) + require.Equal(t, o, wt.skipped) + require.Equal(t, s, wt.written) require.Equal(t, b, w.Bytes()) }) @@ -105,10 +97,8 @@ func TestOffsetWriter(t *testing.T) { require.NoError(t, err) } - wo := wt.(*offsetWriter) - - require.Equal(t, o, wo.skipped) - require.Equal(t, s, wo.written) + require.Equal(t, o, wt.skipped) + require.Equal(t, s, wt.written) require.Equal(t, b, w.Bytes()) }) }