From 1104c96a2fb1ac5e3f224d9ee4f53dc94a51f0c7 Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 22 Jan 2019 11:15:39 +1030 Subject: [PATCH] av/stream/flac: saving progress --- stream/flac/flac_test.go | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/stream/flac/flac_test.go b/stream/flac/flac_test.go index 9537d682..79274819 100644 --- a/stream/flac/flac_test.go +++ b/stream/flac/flac_test.go @@ -38,45 +38,51 @@ const ( outFile = "testOut.wav" ) +// TestWriteSeekerWrite checks that basic writing to the ws works as expected. func TestWriteSeekerWrite(t *testing.T) { - writerSeeker := &writeSeeker{} - var ws io.WriteSeeker = writerSeeker + ws := &writeSeeker{} - ws.Write([]byte("hello")) - if string(writerSeeker.buf) != "hello" { - t.Fail() + const tstStr1 = "hello" + ws.Write([]byte(tstStr1)) + got := string(ws.buf) + if got != tstStr1 { + t.Errorf("Write failed, got: %v, want: %v", got, tstStr1) } - ws.Write([]byte(" world")) - if string(writerSeeker.buf) != "hello world" { - t.Fail() + const tstStr2 = " world" + const want = "hello world" + ws.Write([]byte(tstStr2)) + got = string(ws.buf) + if got != want { + t.Errorf("Second write failed, got: %v, want: %v", got, want) } - } +// TestWriteSeekerSeek checks that writing and seeking works as expected, i.e. we +// can write, then seek to a knew place in the buf, and write again, either replacing +// bytes, or appending bytes. func TestWriteSeekerSeek(t *testing.T) { - writerSeeker := &writeSeeker{} - var ws io.WriteSeeker = writerSeeker + ws := &writeSeeker{} ws.Write([]byte("hello")) - if string(writerSeeker.buf) != "hello" { + if string(ws.buf) != "hello" { t.Fail() } ws.Write([]byte(" world")) - if string(writerSeeker.buf) != "hello world" { + if string(ws.buf) != "hello world" { t.Fail() } ws.Seek(-2, io.SeekEnd) ws.Write([]byte("k!")) - if string(writerSeeker.buf) != "hello work!" { + if string(ws.buf) != "hello work!" { t.Fail() } ws.Seek(6, io.SeekStart) ws.Write([]byte("gopher")) - if string(writerSeeker.buf) != "hello gopher" { + if string(ws.buf) != "hello gopher" { t.Fail() } }