Questions tagged [gomock]

GoMock is a mocking framework for the Go programming language.

GoMock integrates well with Go's built-in testing package, but can be used in other contexts too.

68 questions
0
votes
0 answers

Resolving gomock import cycle

How do I go about resolving an import cycle between github.com/golang/mock/gomock and golang.org/x/net/context? As far as I can tell this cycle exists internally between the two package and I can't modify either of them internally. Currently these…
0
votes
1 answer

How to mock memcache in go lang for unit testing?

I want to mock memcache cache data in go lang to avoid authhorization i tried with gomock but couldn't work out as i dont have any interface for it. func getAccessTokenFromCache(accessToken string) func TestSendData(t *testing.T) { mockCtrl :=…
-1
votes
1 answer

How to mock a file with interface imported from another file

I try to create a mock of a file with an interface imported from another file. I have try with `aux_files` and `imports` but I did non succeed to have a correct mock file. I think I'm missing something. So I have a `mockgen/main.go` like this :…
Kiki
  • 71
  • 8
-1
votes
2 answers

How to mock go-plugin funcs in golang?

# I want to mock this function func testCheckPluginFile(fName string){ plugin, _ := plugin.Open(path.Join("/I/expect/folder/","/plugin-lib-test/"+fName)) plugin.Lookup("symbol") } # So I put this func like this func…
-1
votes
1 answer

Gomock cannot use type map[string]*mockFoo as map[string]foo

I am using gomock, and I have this piece of example code that I wish to test. type StructA struct { client map[string]Foo } type Foo interface { foo.methodFoo() string } func (a *structA) MethodA(name string) string { client :=…
kito
  • 41
  • 7
-1
votes
2 answers

Mocking a non-interface function

I have a Go code something like this func (r *Request) SetRequestMap(ctx *gin.Context, data map[string]interface{}) *Request { //Some processing code id, ok := r.map["id"] if !ok { return r } checkStatus…
Vatz
  • 11
  • 5
-2
votes
1 answer

Using Two Different Mocks in Go Unit Test

I am learning to do unit testing using mocks in Go for the first time, using gomock's mockgen utility. My unit tests work fine except for one of them. The method-under-test has two dependencies: one on a database, and the other on an external…
A.A.
  • 402
  • 1
  • 4
  • 19
-2
votes
1 answer

How to ensure that all Async functions Run before defer is executed

I have a function say Myfunction() { x.RunAsync() //Async Function call } I have to write a test case for Myfunction(). I am using go-mock for this. Also have mocked x. Test_MyFunction() { mockCtrl := gomock.NewController(t) defer…
Arushi
  • 203
  • 1
  • 4
  • 16
1 2 3 4
5