Skip to content

guoshengcc/gomockUnitTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomockUnitTest

learn for gomock

When I execute this command mockgen -source=foo.go, I get this error message :Loading input failed: loading package failed

This is all the script information I executed.

PS C:\GitHub\gomockUnitTest> go get github.com/golang/mock/mockgen@v1.4.4
go: found github.com/golang/mock/mockgen in github.com/golang/mock v1.4.4
PS C:\GitHub\gomockUnitTest> git add .
warning: LF will be replaced by CRLF in go.mod.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in go.sum.
The file will have its original line endings in your working directory
PS C:\GitHub\gomockUnitTest> git commit -m 'get gomock'
[main 6bb7b8e] get gomock
 2 files changed, 11 insertions(+)
 create mode 100644 go.sum
PS C:\GitHub\gomockUnitTest> git add .
PS C:\GitHub\gomockUnitTest> git commit -m 'add ut code'
[main 80098f3] add ut code
 3 files changed, 21 insertions(+)
 create mode 100644 business.go
 create mode 100644 business_test.go
 create mode 100644 foo.go
PS C:\GitHub\gomockUnitTest> mockgen -source=foo.go
2021/02/08 12:09:04 Loading input failed: loading package failed

But,When I execute this command mockgen -source foo.go, I get it. I removed the symbol of =

// Code generated by MockGen. DO NOT EDIT.
// Source: foo.go

// Package mock_main is a generated GoMock package.
package mock_main

import (
        gomock "github.com/golang/mock/gomock"
        reflect "reflect"
)

// MockIfoo is a mock of Ifoo interface
type MockIfoo struct {
        ctrl     *gomock.Controller
        recorder *MockIfooMockRecorder
}

// MockIfooMockRecorder is the mock recorder for MockIfoo
type MockIfooMockRecorder struct {
        mock *MockIfoo
}

// NewMockIfoo creates a new mock instance
func NewMockIfoo(ctrl *gomock.Controller) *MockIfoo {
        mock := &MockIfoo{ctrl: ctrl}
        mock.recorder = &MockIfooMockRecorder{mock}
        return mock
}

// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockIfoo) EXPECT() *MockIfooMockRecorder {
        return m.recorder
}

// GetData mocks base method
func (m *MockIfoo) GetData(id string) (string, error) {
        m.ctrl.T.Helper()
        ret := m.ctrl.Call(m, "GetData", id)
        ret0, _ := ret[0].(string)
        ret1, _ := ret[1].(error)
        return ret0, ret1
}

// GetData indicates an expected call of GetData
func (mr *MockIfooMockRecorder) GetData(id interface{}) *gomock.Call {
        mr.mock.ctrl.T.Helper()
        return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetData", reflect.TypeOf((*MockIfoo)(nil).GetData), id)
}

About

learn for gomock

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages