Standard library / testing/iotest

testing/iotest.TestReader()

Check a reader against expected bytes with varied read sizes; also checks ReaderAt and Seeker if implemented. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func TestReader(r io.Reader, content []byte) error

Parameters & Attributes

NameTypeDescription
rio.ReaderUnderlying reader.
content[]byteExpected complete byte content.

Return Value

error

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings"  "testing/iotest")
func main() {  err := iotest.TestReader(strings.NewReader("abc"), []byte("abc"))  fmt.Println(err == nil)}
Go Reference