diff --git a/hack/vendor.sh b/hack/vendor.sh index cf68582bd2..5d0b6822be 100755 --- a/hack/vendor.sh +++ b/hack/vendor.sh @@ -17,7 +17,7 @@ clone git github.com/mattn/go-sqlite3 v1.1.0 clone git github.com/microsoft/hcsshim 7f646aa6b26bcf90caee91e93cde4a80d0d8a83e clone git github.com/mistifyio/go-zfs v2.1.1 clone git github.com/stretchr/objx cbeaeb16a013161a98496fad62933b1d21786672 -clone git github.com/stretchr/testify 7c2b1e5640dcf2631213ca962d892bffa1e08860 +clone git github.com/stretchr/testify 2b15294402a895a4224659d181866f545991021e clone git github.com/tchap/go-patricia v2.1.0 clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git diff --git a/vendor/src/github.com/stretchr/testify/assert/assertions.go b/vendor/src/github.com/stretchr/testify/assert/assertions.go index 023b1c39a1..22e3a6bb95 100644 --- a/vendor/src/github.com/stretchr/testify/assert/assertions.go +++ b/vendor/src/github.com/stretchr/testify/assert/assertions.go @@ -287,24 +287,10 @@ func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{} // // Returns whether the assertion was successful (true) or not (false). func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { - - success := true - - if object == nil { - success = false - } else { - value := reflect.ValueOf(object) - kind := value.Kind() - if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { - success = false - } + if !isNil(object) { + return true } - - if !success { - Fail(t, "Expected value not to be nil.", msgAndArgs...) - } - - return success + return Fail(t, "Expected value not to be nil.", msgAndArgs...) } // isNil checks if a specified object is nil or not, without Failing. diff --git a/vendor/src/github.com/stretchr/testify/mock/mock.go b/vendor/src/github.com/stretchr/testify/mock/mock.go index 515eec77d0..88ac0eebb5 100644 --- a/vendor/src/github.com/stretchr/testify/mock/mock.go +++ b/vendor/src/github.com/stretchr/testify/mock/mock.go @@ -3,6 +3,7 @@ package mock import ( "fmt" "reflect" + "regexp" "runtime" "strings" "sync" @@ -25,6 +26,7 @@ type TestingT interface { // Call represents a method call and is used for setting expectations, // as well as recording activity. type Call struct { + Parent *Mock // The name of the method that was or will be called. Method string @@ -47,24 +49,113 @@ type Call struct { // Holds a handler used to manipulate arguments content that are passed by // reference. It's useful when mocking methods such as unmarshalers or // decoders. - Run func(Arguments) + RunFn func(Arguments) +} + +func newCall(parent *Mock, methodName string, methodArguments ...interface{}) *Call { + return &Call{ + Parent: parent, + Method: methodName, + Arguments: methodArguments, + ReturnArguments: make([]interface{}, 0), + Repeatability: 0, + WaitFor: nil, + RunFn: nil, + } +} + +func (self *Call) lock() { + self.Parent.mutex.Lock() +} + +func (self *Call) unlock() { + self.Parent.mutex.Unlock() +} + +func (self *Call) Return(returnArguments ...interface{}) *Call { + self.lock() + defer self.unlock() + + self.ReturnArguments = returnArguments + + return self +} + +// Once indicates that that the mock should only return the value once. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Once() +func (self *Call) Once() *Call { + return self.Times(1) +} + +// Twice indicates that that the mock should only return the value twice. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Twice() +func (self *Call) Twice() *Call { + return self.Times(2) +} + +// Times indicates that that the mock should only return the indicated number +// of times. +// +// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Times(5) +func (self *Call) Times(i int) *Call { + self.lock() + defer self.unlock() + self.Repeatability = i + return self +} + +// WaitUntil sets the channel that will block the mock's return until its closed +// or a message is received. +// +// Mock.On("MyMethod", arg1, arg2).WaitUntil(time.After(time.Second)) +func (self *Call) WaitUntil(w <-chan time.Time) *Call { + self.lock() + defer self.unlock() + self.WaitFor = w + return self +} + +// After sets how long to block until the call returns +// +// Mock.On("MyMethod", arg1, arg2).After(time.Second) +func (self *Call) After(d time.Duration) *Call { + return self.WaitUntil(time.After(d)) +} + +// Run sets a handler to be called before returning. It can be used when +// mocking a method such as unmarshalers that takes a pointer to a struct and +// sets properties in such struct +// +// Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}").Return().Run(function(args Arguments) { +// arg := args.Get(0).(*map[string]interface{}) +// arg["foo"] = "bar" +// }) +func (self *Call) Run(fn func(Arguments)) *Call { + self.lock() + defer self.unlock() + self.RunFn = fn + return self +} + +// On chains a new expectation description onto the mocked interface. This +// allows syntax like. +// +// Mock. +// On("MyMethod", 1).Return(nil). +// On("MyOtherMethod", 'a', 'b', 'c').Return(errors.New("Some Error")) +func (self *Call) On(methodName string, arguments ...interface{}) *Call { + return self.Parent.On(methodName, arguments...) } // Mock is the workhorse used to track activity on another object. -// For an example of its usage, refer to the "Example Usage" section at the top of this document. +// For an example of its usage, refer to the "Example Usage" section at the top +// of this document. type Mock struct { - - // The method name that is currently - // being referred to by the On method. - onMethodName string - - // An array of the arguments that are - // currently being referred to by the On method. - onMethodArguments Arguments - // Represents the calls that are expected of // an object. - ExpectedCalls []Call + ExpectedCalls []*Call // Holds the calls that were made to this mocked object. Calls []Call @@ -95,95 +186,23 @@ func (m *Mock) TestData() objx.Map { // being called. // // Mock.On("MyMethod", arg1, arg2) -func (m *Mock) On(methodName string, arguments ...interface{}) *Mock { - m.onMethodName = methodName - m.onMethodArguments = arguments - +func (self *Mock) On(methodName string, arguments ...interface{}) *Call { for _, arg := range arguments { if v := reflect.ValueOf(arg); v.Kind() == reflect.Func { panic(fmt.Sprintf("cannot use Func in expectations. Use mock.AnythingOfType(\"%T\")", arg)) } } - return m + self.mutex.Lock() + defer self.mutex.Unlock() + c := newCall(self, methodName, arguments...) + self.ExpectedCalls = append(self.ExpectedCalls, c) + return c } -// Return finishes a description of an expectation of the method (and arguments) -// specified in the most recent On method call. -// -// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2) -func (m *Mock) Return(returnArguments ...interface{}) *Mock { - m.mutex.Lock() - defer m.mutex.Unlock() - - m.ExpectedCalls = append(m.ExpectedCalls, Call{m.onMethodName, m.onMethodArguments, returnArguments, 0, nil, nil}) - return m -} - -// Once indicates that that the mock should only return the value once. -// -// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Once() -func (m *Mock) Once() { - m.mutex.Lock() - m.ExpectedCalls[len(m.ExpectedCalls)-1].Repeatability = 1 - m.mutex.Unlock() -} - -// Twice indicates that that the mock should only return the value twice. -// -// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Twice() -func (m *Mock) Twice() { - m.mutex.Lock() - m.ExpectedCalls[len(m.ExpectedCalls)-1].Repeatability = 2 - m.mutex.Unlock() -} - -// Times indicates that that the mock should only return the indicated number -// of times. -// -// Mock.On("MyMethod", arg1, arg2).Return(returnArg1, returnArg2).Times(5) -func (m *Mock) Times(i int) { - m.mutex.Lock() - m.ExpectedCalls[len(m.ExpectedCalls)-1].Repeatability = i - m.mutex.Unlock() -} - -// WaitUntil sets the channel that will block the mock's return until its closed -// or a message is received. -// -// Mock.On("MyMethod", arg1, arg2).WaitUntil(time.After(time.Second)) -func (m *Mock) WaitUntil(w <-chan time.Time) *Mock { - m.mutex.Lock() - m.ExpectedCalls[len(m.ExpectedCalls)-1].WaitFor = w - m.mutex.Unlock() - return m -} - -// After sets how long to block until the call returns -// -// Mock.On("MyMethod", arg1, arg2).After(time.Second) -func (m *Mock) After(d time.Duration) *Mock { - return m.WaitUntil(time.After(d)) -} - -// Run sets a handler to be called before returning. It can be used when -// mocking a method such as unmarshalers that takes a pointer to a struct and -// sets properties in such struct -// -// Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}").Return().Run(function(args Arguments) { -// arg := args.Get(0).(*map[string]interface{}) -// arg["foo"] = "bar" -// }) -func (m *Mock) Run(fn func(Arguments)) *Mock { - m.mutex.Lock() - m.ExpectedCalls[len(m.ExpectedCalls)-1].Run = fn - m.mutex.Unlock() - return m -} - -/* - Recording and responding to activity -*/ +// /* +// Recording and responding to activity +// */ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *Call) { for i, call := range m.expectedCalls() { @@ -191,7 +210,7 @@ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, * _, diffCount := call.Arguments.Diff(arguments) if diffCount == 0 { - return i, &call + return i, call } } @@ -209,7 +228,7 @@ func (m *Mock) findClosestCall(method string, arguments ...interface{}) (bool, * _, tempDiffCount := call.Arguments.Diff(arguments) if tempDiffCount < diffCount || diffCount == 0 { diffCount = tempDiffCount - closestCall = &call + closestCall = call } } @@ -247,6 +266,14 @@ func (m *Mock) Called(arguments ...interface{}) Arguments { panic("Couldn't get the caller information") } functionPath := runtime.FuncForPC(pc).Name() + //Next four lines are required to use GCCGO function naming conventions. + //For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock + //uses inteface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree + //With GCCGO we need to remove interface information starting from pN