testio: linting fixes
This commit is contained in:
@@ -169,6 +169,26 @@ type BufCloser struct {
|
|||||||
buf *bytes.Buffer
|
buf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBufCloser creates and initializes a new BufCloser using buf as
|
||||||
|
// its initial contents. It is intended to prepare a BufCloser to read
|
||||||
|
// existing data. It can also be used to size the internal buffer for
|
||||||
|
// writing. To do that, buf should have the desired capacity but a
|
||||||
|
// length of zero.
|
||||||
|
func NewBufCloser(buf []byte) *BufCloser {
|
||||||
|
bc := new(BufCloser)
|
||||||
|
bc.buf = bytes.NewBuffer(buf)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBufCloserString creates and initializes a new Buffer using
|
||||||
|
// string s as its initial contents. It is intended to prepare a
|
||||||
|
// buffer to read an existing string.
|
||||||
|
func NewBufCloserString(s string) *BufCloser {
|
||||||
|
buf := new(BufCloser)
|
||||||
|
buf.buf = bytes.NewBufferString(s)
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
// Write writes the data to the BufCloser.
|
// Write writes the data to the BufCloser.
|
||||||
func (buf *BufCloser) Write(p []byte) (int, error) {
|
func (buf *BufCloser) Write(p []byte) (int, error) {
|
||||||
return buf.buf.Write(p)
|
return buf.buf.Write(p)
|
||||||
@@ -199,26 +219,6 @@ func (buf *BufCloser) Len() int {
|
|||||||
return buf.buf.Len()
|
return buf.buf.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBufCloser creates and initializes a new BufCloser using buf as
|
|
||||||
// its initial contents. It is intended to prepare a BufCloser to read
|
|
||||||
// existing data. It can also be used to size the internal buffer for
|
|
||||||
// writing. To do that, buf should have the desired capacity but a
|
|
||||||
// length of zero.
|
|
||||||
func NewBufCloser(buf []byte) *BufCloser {
|
|
||||||
bc := new(BufCloser)
|
|
||||||
bc.buf = bytes.NewBuffer(buf)
|
|
||||||
return bc
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBufCloserString creates and initializes a new Buffer using
|
|
||||||
// string s as its initial contents. It is intended to prepare a
|
|
||||||
// buffer to read an existing string.
|
|
||||||
func NewBufCloserString(s string) *BufCloser {
|
|
||||||
buf := new(BufCloser)
|
|
||||||
buf.buf = bytes.NewBufferString(s)
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// A LoggingBuffer is an io.ReadWriter that prints the hex value of
|
// A LoggingBuffer is an io.ReadWriter that prints the hex value of
|
||||||
// the data for all reads and writes.
|
// the data for all reads and writes.
|
||||||
type LoggingBuffer struct {
|
type LoggingBuffer struct {
|
||||||
@@ -323,6 +323,26 @@ type BrokenCloser struct {
|
|||||||
buf *bytes.Buffer
|
buf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBrokenCloser creates and initializes a new BrokenCloser using buf as
|
||||||
|
// its initial contents. It is intended to prepare a BrokenCloser to read
|
||||||
|
// existing data. It can also be used to size the internal buffer for
|
||||||
|
// writing. To do that, buf should have the desired capacity but a
|
||||||
|
// length of zero.
|
||||||
|
func NewBrokenCloser(buf []byte) *BrokenCloser {
|
||||||
|
bc := new(BrokenCloser)
|
||||||
|
bc.buf = bytes.NewBuffer(buf)
|
||||||
|
return bc
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBrokenCloserString creates and initializes a new Buffer using
|
||||||
|
// string s as its initial contents. It is intended to prepare a
|
||||||
|
// buffer to read an existing string.
|
||||||
|
func NewBrokenCloserString(s string) *BrokenCloser {
|
||||||
|
buf := new(BrokenCloser)
|
||||||
|
buf.buf = bytes.NewBufferString(s)
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
// Write writes the data to the BrokenCloser.
|
// Write writes the data to the BrokenCloser.
|
||||||
func (buf *BrokenCloser) Write(p []byte) (int, error) {
|
func (buf *BrokenCloser) Write(p []byte) (int, error) {
|
||||||
return buf.buf.Write(p)
|
return buf.buf.Write(p)
|
||||||
@@ -347,23 +367,3 @@ func (buf *BrokenCloser) Reset() {
|
|||||||
func (buf *BrokenCloser) Bytes() []byte {
|
func (buf *BrokenCloser) Bytes() []byte {
|
||||||
return buf.buf.Bytes()
|
return buf.buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBrokenCloser creates and initializes a new BrokenCloser using buf as
|
|
||||||
// its initial contents. It is intended to prepare a BrokenCloser to read
|
|
||||||
// existing data. It can also be used to size the internal buffer for
|
|
||||||
// writing. To do that, buf should have the desired capacity but a
|
|
||||||
// length of zero.
|
|
||||||
func NewBrokenCloser(buf []byte) *BrokenCloser {
|
|
||||||
bc := new(BrokenCloser)
|
|
||||||
bc.buf = bytes.NewBuffer(buf)
|
|
||||||
return bc
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBrokenCloserString creates and initializes a new Buffer using
|
|
||||||
// string s as its initial contents. It is intended to prepare a
|
|
||||||
// buffer to read an existing string.
|
|
||||||
func NewBrokenCloserString(s string) *BrokenCloser {
|
|
||||||
buf := new(BrokenCloser)
|
|
||||||
buf.buf = bytes.NewBufferString(s)
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
package testio
|
package testio_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.wntrmute.dev/kyle/goutils/testio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBrokenWriter(t *testing.T) {
|
func TestBrokenWriter(t *testing.T) {
|
||||||
buf := NewBrokenWriter(2)
|
buf := testio.NewBrokenWriter(2)
|
||||||
data := []byte{1, 2}
|
data := []byte{1, 2}
|
||||||
|
|
||||||
n, err := buf.Write(data)
|
n, err := buf.Write(data)
|
||||||
@@ -39,7 +41,7 @@ func TestBufCloser(t *testing.T) {
|
|||||||
var data = []byte{1, 2}
|
var data = []byte{1, 2}
|
||||||
var read = make([]byte, 2)
|
var read = make([]byte, 2)
|
||||||
|
|
||||||
buf := NewBufCloser(data)
|
buf := testio.NewBufCloser(data)
|
||||||
_, err := buf.Read(read)
|
_, err := buf.Read(read)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
@@ -54,7 +56,7 @@ func TestBufCloser(t *testing.T) {
|
|||||||
buf.Reset()
|
buf.Reset()
|
||||||
|
|
||||||
s := "hi"
|
s := "hi"
|
||||||
buf = NewBufCloserString(s)
|
buf = testio.NewBufCloserString(s)
|
||||||
|
|
||||||
read = buf.Bytes()
|
read = buf.Bytes()
|
||||||
if string(read) != s {
|
if string(read) != s {
|
||||||
@@ -65,7 +67,7 @@ func TestBufCloser(t *testing.T) {
|
|||||||
func TestLoggingBuffer(t *testing.T) {
|
func TestLoggingBuffer(t *testing.T) {
|
||||||
src := &bytes.Buffer{}
|
src := &bytes.Buffer{}
|
||||||
data := []byte("AB")
|
data := []byte("AB")
|
||||||
lb := NewLoggingBuffer(src)
|
lb := testio.NewLoggingBuffer(src)
|
||||||
_, err := lb.Write(data)
|
_, err := lb.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
@@ -82,8 +84,8 @@ func TestLoggingBuffer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected := "[TEST] [WRITE] 4142\n"
|
expected := "[TEST] [WRITE] 4142\n"
|
||||||
if string(out.Bytes()) != expected {
|
if out.String() != expected {
|
||||||
t.Fatalf("expected '%s', have '%s'", expected, string(out.Bytes()))
|
t.Fatalf("expected '%s', have '%s'", expected, out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Reset()
|
out.Reset()
|
||||||
@@ -96,8 +98,8 @@ func TestLoggingBuffer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected = "[TEST] [READ] 4142\n"
|
expected = "[TEST] [READ] 4142\n"
|
||||||
if string(out.Bytes()) != expected {
|
if out.String() != expected {
|
||||||
t.Fatalf("expected '%s', have '%s'", expected, string(out.Bytes()))
|
t.Fatalf("expected '%s', have '%s'", expected, out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Reset()
|
out.Reset()
|
||||||
@@ -112,8 +114,8 @@ func TestLoggingBuffer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected = "[READ] 4142\n"
|
expected = "[READ] 4142\n"
|
||||||
if string(out.Bytes()) != expected {
|
if out.String() != expected {
|
||||||
t.Fatalf("expected '%s', have '%s'", expected, string(out.Bytes()))
|
t.Fatalf("expected '%s', have '%s'", expected, out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
src.Reset()
|
src.Reset()
|
||||||
@@ -124,8 +126,8 @@ func TestLoggingBuffer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBrokenReadWriter(t *testing.T) {
|
func TestBrokenReadWriter(t *testing.T) {
|
||||||
brw := NewBrokenReadWriter(0, 0)
|
brw := testio.NewBrokenReadWriter(0, 0)
|
||||||
lb := NewLoggingBuffer(brw)
|
lb := testio.NewLoggingBuffer(brw)
|
||||||
|
|
||||||
var p = make([]byte, 2)
|
var p = make([]byte, 2)
|
||||||
var data = []byte("HI")
|
var data = []byte("HI")
|
||||||
@@ -177,7 +179,7 @@ func TestBrokenReadWriter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBufferConn(t *testing.T) {
|
func TestBufferConn(t *testing.T) {
|
||||||
bc := NewBufferConn()
|
bc := testio.NewBufferConn()
|
||||||
|
|
||||||
client := []byte("AB")
|
client := []byte("AB")
|
||||||
peer := []byte("XY")
|
peer := []byte("XY")
|
||||||
|
|||||||
Reference in New Issue
Block a user