I am trying to write some tests for an existing library but cannot get gomock to work
I would like to test behaviour if rand.Read fails. Here is an example of what I would like to test. I would like to see the log.Error line executing in test
import (
"crypto/rand"
)
func GetRandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
log.Error("Failed to get entropy from system", err)
return nil, err
}
return b, nil
}
The gomock system should let me force the "rand.Read" call to do the right thing
However, I cannot get the mockgen tool to work in "reflect" mode
$ $GOPATH/bin/mockgen 'crypto/rand' Read
# command-line-arguments
./prog.go:22:28: invalid indirect of "crypto/rand".Read (type func([]byte) (int, error))
2018/01/21 11:20:30 Loading input failed: exit status 2
I'm using go version go1.9.2 linux/amd64 on Ubuntu 14.04
genmock -prog_only 'crypto/rand' Read
works fine, but the code it generates doesn't look useful for what I need to do