Standard library / testing/iotest

testing/iotest.OneByteReader()

Limit each nonempty read to one byte, exposing assumptions about full buffers. Expected stdout: 'a true\n'.

Formal Syntax & Structure

go syntaxgo
func OneByteReader(r io.Reader) io.Reader

Parameters & Attributes

NameTypeDescription
rio.ReaderUnderlying reader.

Return Value

io.Reader

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings"  "testing/iotest")
func main() {  r := iotest.OneByteReader(strings.NewReader("abc"))  b := make([]byte, 8)  n, err := r.Read(b)  fmt.Println(string(b[:n]), err == nil)}
Go Reference