Standard library / testing/iotest
testing/iotest.DataErrReader()
Return final data together with the terminal read error, exercising readers that must handle n before err. Expected stdout: 'abc true\n'.
Formal Syntax & Structure
go syntaxgo
func DataErrReader(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" "io" "strings" "testing/iotest")
func main() { r := iotest.DataErrReader(strings.NewReader("abc")) b := make([]byte, 8) n, err := r.Read(b) fmt.Println(string(b[:n]), err == io.EOF)}