Skip to content

ktnyt/iomock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iomock

Mock Go io interfaces.

Usage

Install

Add iomock to your project.

go get github.com/ktnyt/iomock

Mock a read error

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))
}

Mock a write error

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")))
}

About

Mock Go io interfaces.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages