1

Project structure

  • ~/vscodego - has go.mod and go.sum and one .go file
  • ~/vscodego/testfiles has heap1_test.go test1_file_test.go

Under the directory ~vscodego/testfiles, trying to generate mock for interface that is in the file heap1_test.go

Command and error as below

princes-MBP:testfiles prince$ mockgen --build_flags=--mod=mod . MyStructIntf 
vscodego/testfiles: no non-test Go files in /Users/prince/vscodego/testfiles
vscodego/testfiles: no non-test Go files in /Users/prince/vscodego/testfiles
go: finding module for package go.uber.org/mock/mockgen/model
prog.go:14:2: package vscodego/testfiles is not in GOROOT (/usr/local/Cellar/go/1.20.5/libexec/src/vscodego/testfiles)
2023/07/07 17:11:32 Loading input failed: exit status 1
princes-MBP:testfiles prince$ 

Contents of the test file heap1_test.go

package testfiles

import "testing"

type MyStruct struct {
    age  int
    Name string
}

func (m *MyStruct) getName() string {
    return m.Name
}

type MyStructIntf interface {
    getName() string
}

func TestHeap1(t *testing.T) {

}
curiousengineer
  • 2,196
  • 5
  • 40
  • 59

1 Answers1

0

mockgen needs two arguments, an import path, and a symbol/symbols.

include the import path as <your_module_name>/testfiles

mockgen --build_flags=--mod=mod <your_module_name>/testfiles MyStructIntf
Sapan V
  • 271
  • 1
  • 9