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) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.Reader | Underlying reader. |
| content | []byte | Expected 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)}