vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood 2018-01-16 13:20:59 +00:00
parent 8e83fb6fb9
commit 7d3a17725d
4878 changed files with 1974229 additions and 201215 deletions

View file

@ -2,6 +2,8 @@ package mock
import (
"errors"
"fmt"
"sync"
"testing"
"time"
@ -41,6 +43,26 @@ func (i *TestExampleImplementation) TheExampleMethod3(et *ExampleType) error {
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethod4(v ExampleInterface) error {
args := i.Called(v)
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethod5(ch chan struct{}) error {
args := i.Called(ch)
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethod6(m map[string]bool) error {
args := i.Called(m)
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethod7(slice []bool) error {
args := i.Called(slice)
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethodFunc(fn func(string) error) error {
args := i.Called(fn)
return args.Error(0)
@ -180,15 +202,20 @@ func Test_Mock_On_WithPtrArgMatcher(t *testing.T) {
var mockedService TestExampleImplementation
mockedService.On("TheExampleMethod3",
MatchedBy(func(a *ExampleType) bool { return a.ran == true }),
MatchedBy(func(a *ExampleType) bool { return a != nil && a.ran == true }),
).Return(nil)
mockedService.On("TheExampleMethod3",
MatchedBy(func(a *ExampleType) bool { return a.ran == false }),
MatchedBy(func(a *ExampleType) bool { return a != nil && a.ran == false }),
).Return(errors.New("error"))
mockedService.On("TheExampleMethod3",
MatchedBy(func(a *ExampleType) bool { return a == nil }),
).Return(errors.New("error2"))
assert.Equal(t, mockedService.TheExampleMethod3(&ExampleType{true}), nil)
assert.EqualError(t, mockedService.TheExampleMethod3(&ExampleType{false}), "error")
assert.EqualError(t, mockedService.TheExampleMethod3(nil), "error2")
}
func Test_Mock_On_WithFuncArgMatcher(t *testing.T) {
@ -197,17 +224,62 @@ func Test_Mock_On_WithFuncArgMatcher(t *testing.T) {
fixture1, fixture2 := errors.New("fixture1"), errors.New("fixture2")
mockedService.On("TheExampleMethodFunc",
MatchedBy(func(a func(string) error) bool { return a("string") == fixture1 }),
MatchedBy(func(a func(string) error) bool { return a != nil && a("string") == fixture1 }),
).Return(errors.New("fixture1"))
mockedService.On("TheExampleMethodFunc",
MatchedBy(func(a func(string) error) bool { return a("string") == fixture2 }),
MatchedBy(func(a func(string) error) bool { return a != nil && a("string") == fixture2 }),
).Return(errors.New("fixture2"))
mockedService.On("TheExampleMethodFunc",
MatchedBy(func(a func(string) error) bool { return a == nil }),
).Return(errors.New("fixture3"))
assert.EqualError(t, mockedService.TheExampleMethodFunc(
func(string) error { return fixture1 }), "fixture1")
assert.EqualError(t, mockedService.TheExampleMethodFunc(
func(string) error { return fixture2 }), "fixture2")
assert.EqualError(t, mockedService.TheExampleMethodFunc(nil), "fixture3")
}
func Test_Mock_On_WithInterfaceArgMatcher(t *testing.T) {
var mockedService TestExampleImplementation
mockedService.On("TheExampleMethod4",
MatchedBy(func(a ExampleInterface) bool { return a == nil }),
).Return(errors.New("fixture1"))
assert.EqualError(t, mockedService.TheExampleMethod4(nil), "fixture1")
}
func Test_Mock_On_WithChannelArgMatcher(t *testing.T) {
var mockedService TestExampleImplementation
mockedService.On("TheExampleMethod5",
MatchedBy(func(ch chan struct{}) bool { return ch == nil }),
).Return(errors.New("fixture1"))
assert.EqualError(t, mockedService.TheExampleMethod5(nil), "fixture1")
}
func Test_Mock_On_WithMapArgMatcher(t *testing.T) {
var mockedService TestExampleImplementation
mockedService.On("TheExampleMethod6",
MatchedBy(func(m map[string]bool) bool { return m == nil }),
).Return(errors.New("fixture1"))
assert.EqualError(t, mockedService.TheExampleMethod6(nil), "fixture1")
}
func Test_Mock_On_WithSliceArgMatcher(t *testing.T) {
var mockedService TestExampleImplementation
mockedService.On("TheExampleMethod7",
MatchedBy(func(slice []bool) bool { return slice == nil }),
).Return(errors.New("fixture1"))
assert.EqualError(t, mockedService.TheExampleMethod7(nil), "fixture1")
}
func Test_Mock_On_WithVariadicFunc(t *testing.T) {
@ -998,6 +1070,31 @@ func Test_Mock_AssertNotCalled(t *testing.T) {
}
func Test_Mock_AssertOptional(t *testing.T) {
// Optional called
var ms1 = new(TestExampleImplementation)
ms1.On("TheExampleMethod", 1, 2, 3).Maybe().Return(4, nil)
ms1.TheExampleMethod(1, 2, 3)
tt1 := new(testing.T)
assert.Equal(t, true, ms1.AssertExpectations(tt1))
// Optional not called
var ms2 = new(TestExampleImplementation)
ms2.On("TheExampleMethod", 1, 2, 3).Maybe().Return(4, nil)
tt2 := new(testing.T)
assert.Equal(t, true, ms2.AssertExpectations(tt2))
// Non-optional called
var ms3 = new(TestExampleImplementation)
ms3.On("TheExampleMethod", 1, 2, 3).Return(4, nil)
ms3.TheExampleMethod(1, 2, 3)
tt3 := new(testing.T)
assert.Equal(t, true, ms3.AssertExpectations(tt3))
}
/*
Arguments helper methods
*/
@ -1195,3 +1292,61 @@ func Test_MockMethodCalled(t *testing.T) {
require.Equal(t, "world", retArgs[0])
m.AssertExpectations(t)
}
// Test to validate fix for racy concurrent call access in MethodCalled()
func Test_MockReturnAndCalledConcurrent(t *testing.T) {
iterations := 1000
m := &Mock{}
call := m.On("ConcurrencyTestMethod")
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
for i := 0; i < iterations; i++ {
call.Return(10)
}
wg.Done()
}()
go func() {
for i := 0; i < iterations; i++ {
ConcurrencyTestMethod(m)
}
wg.Done()
}()
wg.Wait()
}
type timer struct{ Mock }
func (s *timer) GetTime(i int) string {
return s.Called(i).Get(0).(string)
}
func TestAfterTotalWaitTimeWhileExecution(t *testing.T) {
waitDuration := 1
total, waitMs := 5, time.Millisecond*time.Duration(waitDuration)
aTimer := new(timer)
for i := 0; i < total; i++ {
aTimer.On("GetTime", i).After(waitMs).Return(fmt.Sprintf("Time%d", i)).Once()
}
time.Sleep(waitMs)
start := time.Now()
var results []string
for i := 0; i < total; i++ {
results = append(results, aTimer.GetTime(i))
}
end := time.Now()
elapsedTime := end.Sub(start)
assert.True(t, elapsedTime > waitMs, fmt.Sprintf("Total elapsed time:%v should be atleast greater than %v", elapsedTime, waitMs))
assert.Equal(t, total, len(results))
for i, _ := range results {
assert.Equal(t, fmt.Sprintf("Time%d", i), results[i], "Return value of method should be same")
}
}
func ConcurrencyTestMethod(m *Mock) {
m.Called()
}