added go generate with vendor test
This commit is contained in:
parent
3dc8438cf7
commit
595a9745ee
@ -2,7 +2,9 @@ package moq
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -240,3 +242,31 @@ func TestEmptyInterface(t *testing.T) {
|
||||
t.Error("contains sync import, although this package isn't used")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoGenerateVendoredPackages(t *testing.T) {
|
||||
cmd := exec.Command("go", "generate", "./...")
|
||||
cmd.Dir = "testpackages/gogenvendoring"
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Errorf("StdoutPipe: %s", err)
|
||||
}
|
||||
defer stdout.Close()
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
t.Errorf("Start: %s", err)
|
||||
}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
io.Copy(buf, stdout)
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
t.Errorf("Wait: %s %s", exitErr, string(exitErr.Stderr))
|
||||
} else {
|
||||
t.Errorf("Wait: %s", err)
|
||||
}
|
||||
}
|
||||
s := buf.String()
|
||||
if strings.Contains(s, `vendor/`) {
|
||||
t.Error("contains vendor directory in import path")
|
||||
}
|
||||
}
|
||||
|
73
pkg/moq/testpackages/dotimport/service_moq_test.go
Executable file
73
pkg/moq/testpackages/dotimport/service_moq_test.go
Executable file
@ -0,0 +1,73 @@
|
||||
// Code generated by moq; DO NOT EDIT
|
||||
// github.com/matryer/moq
|
||||
|
||||
package dotimport_test
|
||||
|
||||
import (
|
||||
"github.com/matryer/moq/pkg/moq/testpackages/dotimport"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
lockServiceMockUser sync.RWMutex
|
||||
)
|
||||
|
||||
// ServiceMock is a mock implementation of Service.
|
||||
//
|
||||
// func TestSomethingThatUsesService(t *testing.T) {
|
||||
//
|
||||
// // make and configure a mocked Service
|
||||
// mockedService := &ServiceMock{
|
||||
// UserFunc: func(ID string) (dotimport.User, error) {
|
||||
// panic("TODO: mock out the User method")
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// // TODO: use mockedService in code that requires Service
|
||||
// // and then make assertions.
|
||||
//
|
||||
// }
|
||||
type ServiceMock struct {
|
||||
// UserFunc mocks the User method.
|
||||
UserFunc func(ID string) (dotimport.User, error)
|
||||
|
||||
// calls tracks calls to the methods.
|
||||
calls struct {
|
||||
// User holds details about calls to the User method.
|
||||
User []struct {
|
||||
// ID is the ID argument value.
|
||||
ID string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User calls UserFunc.
|
||||
func (mock *ServiceMock) User(ID string) (dotimport.User, error) {
|
||||
if mock.UserFunc == nil {
|
||||
panic("moq: ServiceMock.UserFunc is nil but Service.User was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
ID string
|
||||
}{
|
||||
ID: ID,
|
||||
}
|
||||
lockServiceMockUser.Lock()
|
||||
mock.calls.User = append(mock.calls.User, callInfo)
|
||||
lockServiceMockUser.Unlock()
|
||||
return mock.UserFunc(ID)
|
||||
}
|
||||
|
||||
// UserCalls gets all the calls that were made to User.
|
||||
// Check the length with:
|
||||
// len(mockedService.UserCalls())
|
||||
func (mock *ServiceMock) UserCalls() []struct {
|
||||
ID string
|
||||
} {
|
||||
var calls []struct {
|
||||
ID string
|
||||
}
|
||||
lockServiceMockUser.RLock()
|
||||
calls = mock.calls.User
|
||||
lockServiceMockUser.RUnlock()
|
||||
return calls
|
||||
}
|
10
pkg/moq/testpackages/gogenvendoring/user/user.go
Normal file
10
pkg/moq/testpackages/gogenvendoring/user/user.go
Normal file
@ -0,0 +1,10 @@
|
||||
package user
|
||||
|
||||
import "github.com/matryer/somerepo"
|
||||
|
||||
//go:generate moq . Service
|
||||
|
||||
// Service does something good with computers.
|
||||
type Service interface {
|
||||
DoSomething(somerepo.SomeType) error
|
||||
}
|
3
pkg/vendor/github.com/matryer/somerepo/yep.go
generated
vendored
Normal file
3
pkg/vendor/github.com/matryer/somerepo/yep.go
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package somerepo
|
||||
|
||||
type SomeType string
|
Loading…
Reference in New Issue
Block a user