Merge branch 'master' into appease-golint

This commit is contained in:
Mat Ryer 2017-12-06 15:07:50 +00:00 committed by GitHub
commit acbb9b7883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 0 deletions

View File

@ -2,7 +2,9 @@ package moq
import (
"bytes"
"io"
"os"
"os/exec"
"strings"
"testing"
)
@ -241,3 +243,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")
}
}

View 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
}

View 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
View File

@ -0,0 +1,3 @@
package somerepo
type SomeType string