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.ReaderParameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.Reader | Underlying 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)}