Standard library / testing/iotest
testing/iotest.HalfReader()
Limit a read to about half of the requested buffer (rounding up). Expected stdout: 'abc true\n'.
Formal Syntax & Structure
go syntaxgo
func HalfReader(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.HalfReader(strings.NewReader("abcdef")) b := make([]byte, 5) n, err := r.Read(b) fmt.Println(string(b[:n]), err == nil)}