Mock Go io interfaces.
Add iomock to your project.
go get github.com/ktnyt/iomock
package main
import (
"fmt"
"io"
"github.com/ktnyt/iomock"
)
func main() {
r := iomock.NewReader(func(p []byte) (int, error) {
return 0, io.ErrClosedPipe
})
p := make([]byte, 3)
// Output: 0 io: read/write on closed pipe
fmt.Println(r.Read(p))
}
package main
import (
"fmt"
"io"
"github.com/ktnyt/iomock"
)
func main() {
w := iomock.NewWriter(func(p []byte) (int, error) {
return 0, io.ErrClosedPipe
})
// Output: 0 io: read/write on closed pipe
fmt.Println(w.Write([]byte("foo")))
}