* Internal registry for disambiguated imports, vars - Move functionality in the moq package partially into internal/{registry,template}. - Leverage registry to assign unique package and variable/method parameter names. Use import aliases if present in interface source package. BREAKING CHANGE: When the interface definition does not mention the parameter names, the field names in call info anonymous struct will be different. The new field names are generated using the type info (string -> s, int -> n, chan int -> intCh, []MyType -> myTypes, map[string]int -> stringToInt etc.). For example, for a string parameter previously if the field name was 'In1', the new field could be 'S' or 'S1' (depends on number of string method parameters). * Refactor golden file tests to be table-driven * Fix sync pkg alias handling for moq generation * Improve, add tests (increase coverage) * Use $.Foo in template, avoid declaring variables $ is set to the data argument passed to Execute, that is, to the starting value of dot. Variables were declared to be able to refer to the parent context. * Consistent template field formatting * Use tabs in generated Godoc comments' example code * Minor simplification * go generate * Fix conflict for generated param name of pointer type Excellent work by @sudo-suhas.
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
// Code generated by moq; DO NOT EDIT.
|
|
// github.com/matryer/moq
|
|
|
|
package mock
|
|
|
|
import (
|
|
shadowhttp "github.com/matryer/moq/pkg/moq/testpackages/shadow/http"
|
|
nethttp "net/http"
|
|
"sync"
|
|
)
|
|
|
|
// Ensure, that ThingMock does implement shadowhttp.Thing.
|
|
// If this is not the case, regenerate this file with moq.
|
|
var _ shadowhttp.Thing = &ThingMock{}
|
|
|
|
// ThingMock is a mock implementation of shadowhttp.Thing.
|
|
//
|
|
// func TestSomethingThatUsesThing(t *testing.T) {
|
|
//
|
|
// // make and configure a mocked shadowhttp.Thing
|
|
// mockedThing := &ThingMock{
|
|
// BlahFunc: func(w nethttp.ResponseWriter, r *nethttp.Request) {
|
|
// panic("mock out the Blah method")
|
|
// },
|
|
// }
|
|
//
|
|
// // use mockedThing in code that requires shadowhttp.Thing
|
|
// // and then make assertions.
|
|
//
|
|
// }
|
|
type ThingMock struct {
|
|
// BlahFunc mocks the Blah method.
|
|
BlahFunc func(w nethttp.ResponseWriter, r *nethttp.Request)
|
|
|
|
// calls tracks calls to the methods.
|
|
calls struct {
|
|
// Blah holds details about calls to the Blah method.
|
|
Blah []struct {
|
|
// W is the w argument value.
|
|
W nethttp.ResponseWriter
|
|
// R is the r argument value.
|
|
R *nethttp.Request
|
|
}
|
|
}
|
|
lockBlah sync.RWMutex
|
|
}
|
|
|
|
// Blah calls BlahFunc.
|
|
func (mock *ThingMock) Blah(w nethttp.ResponseWriter, r *nethttp.Request) {
|
|
if mock.BlahFunc == nil {
|
|
panic("ThingMock.BlahFunc: method is nil but Thing.Blah was just called")
|
|
}
|
|
callInfo := struct {
|
|
W nethttp.ResponseWriter
|
|
R *nethttp.Request
|
|
}{
|
|
W: w,
|
|
R: r,
|
|
}
|
|
mock.lockBlah.Lock()
|
|
mock.calls.Blah = append(mock.calls.Blah, callInfo)
|
|
mock.lockBlah.Unlock()
|
|
mock.BlahFunc(w, r)
|
|
}
|
|
|
|
// BlahCalls gets all the calls that were made to Blah.
|
|
// Check the length with:
|
|
// len(mockedThing.BlahCalls())
|
|
func (mock *ThingMock) BlahCalls() []struct {
|
|
W nethttp.ResponseWriter
|
|
R *nethttp.Request
|
|
} {
|
|
var calls []struct {
|
|
W nethttp.ResponseWriter
|
|
R *nethttp.Request
|
|
}
|
|
mock.lockBlah.RLock()
|
|
calls = mock.calls.Blah
|
|
mock.lockBlah.RUnlock()
|
|
return calls
|
|
}
|