DEV Community

Discussion on: Mock DB for testing HTTP API in Go and achieve 100% coverage

Collapse
 
acetorscode profile image
Apoorv Mishra

Hey while running the mockgen command to create mock file, i am getting below error, do you have any idea why is there this error, it says go mod file not found, but it is present there.
missing go.sum entry for module providing package github.com/golang/mock/mockgen/model; to add:
go mod download github.com/golang/mock
prog.go:12:2: missing go.sum entry for module providing package github.com/golang/mock/mockgen/model; to add:
go mod download github.com/golang/mock
prog.go:14:2: no required module provides package github.com/acetorscode/learningbank/db/sqlc: go.mod file not found in current directory or any parent directory; see 'go help modules'
prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules'
2021/05/31 19:12:53 Loading input failed: exit status 1

Collapse
 
phihdn profile image
Phi Hoang

As the readme on their github repo, there are some workaround solutions:

  1. Include an empty import import _ "github.com/golang/mock/mockgen/model".
  2. Add --build_flags=--mod=mod to your mockgen command.

I had the same error as you and I did the second one successfully.
mockgen -build_flags=--mod=mod -package mockdb -destination db/mock/store.go github.com/phihdn/simplebank/db/sqlc Store

Collapse
 
devtianze profile image
Tianze Hua

thank you so so much, I registered just here to say thank you. How are you able to find this solution? I searched for long didn't find a usable solution lol

Thread Thread
 
phihdn profile image
Phi Hoang

Hi, I don't remember. It might be Google or I might walk around their github Issues page. Then I found it in the readme. :) happy to hear it helps.