matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
1.96k stars 126 forks source link

Generate mock for external library #172

Closed alexisvisco closed 2 years ago

alexisvisco commented 2 years ago

Hi, I am wondering if it's possible to generates mock for external library, if it's possible how to do it ?

breml commented 2 years ago

In some cases, I used type aliases for this use case like this:

package myreader

import "io"

//go:generate moq -out reader_mock.go . Reader

type Reader = io.Reader
matryer commented 2 years ago

thanks @breml - another option is to copy the interface into your own project. This isn't a hack per se, some people like to do this anyway as it allows them to provide multiple implementations of something in their project.