Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate value fields #108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions generator/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ type Fake struct {

// Method is a method of the interface.
type Method struct {
FakeName string
FakePackage string
Name string
Params Params
Returns Returns
Name string
Params Params
Returns Returns
}

// NewFake returns a Fake that loads the package and finds the interface or the
Expand Down
3 changes: 1 addition & 2 deletions generator/function_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func (f *Fake) loadMethodForFunction() error {
}
f.addTypesForMethod(sig)
importsMap := f.importsMap()
function := methodForSignature(sig, f.Name, f.TargetAlias, f.TargetName, importsMap)
f.Function = function
f.Function = methodForSignature(sig, f.TargetName, importsMap)
return nil
}
14 changes: 7 additions & 7 deletions generator/function_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type {{.Name}} struct {
invocationsMutex sync.RWMutex
}

func (fake *{{.Function.FakeName}}) Spy({{.Function.Params.AsNamedArgsWithTypes}}) {{.Function.Returns.AsReturnSignature}} {
func (fake *{{.Name}}) Spy({{.Function.Params.AsNamedArgsWithTypes}}) {{.Function.Returns.AsReturnSignature}} {
{{- range .Function.Params.Slices}}
var {{UnExport .Name}}Copy {{.Type}}
if {{UnExport .Name}} != nil {
Expand Down Expand Up @@ -73,28 +73,28 @@ func (fake *{{.Function.FakeName}}) Spy({{.Function.Params.AsNamedArgsWithTypes}
{{- end}}
}

func (fake *{{.Function.FakeName}}) CallCount() int {
func (fake *{{.Name}}) CallCount() int {
fake.mutex.RLock()
defer fake.mutex.RUnlock()
return len(fake.argsForCall)
}

func (fake *{{.Function.FakeName}}) Calls(stub func({{.Function.Params.AsArgs}}) {{.Function.Returns.AsReturnSignature}}) {
func (fake *{{.Name}}) Calls(stub func({{.Function.Params.AsArgs}}) {{.Function.Returns.AsReturnSignature}}) {
fake.mutex.Lock()
defer fake.mutex.Unlock()
fake.Stub = stub
}

{{if .Function.Params.HasLength -}}
func (fake *{{.Function.FakeName}}) ArgsForCall(i int) {{.Function.Params.AsReturnSignature}} {
func (fake *{{.Name}}) ArgsForCall(i int) {{.Function.Params.AsReturnSignature}} {
fake.mutex.RLock()
defer fake.mutex.RUnlock()
return {{.Function.Params.WithPrefix "fake.argsForCall[i]."}}
}
{{- end}}

{{if .Function.Returns.HasLength -}}
func (fake *{{.Function.FakeName}}) Returns({{.Function.Returns.AsNamedArgsWithTypes}}) {
func (fake *{{.Name}}) Returns({{.Function.Returns.AsNamedArgsWithTypes}}) {
fake.mutex.Lock()
defer fake.mutex.Unlock()
fake.Stub = nil
Expand All @@ -105,7 +105,7 @@ func (fake *{{.Function.FakeName}}) Returns({{.Function.Returns.AsNamedArgsWithT
}{ {{- .Function.Returns.AsNamedArgs -}} }
}

func (fake *{{.Function.FakeName}}) ReturnsOnCall(i int, {{.Function.Returns.AsNamedArgsWithTypes}}) {
func (fake *{{.Name}}) ReturnsOnCall(i int, {{.Function.Returns.AsNamedArgsWithTypes}}) {
fake.mutex.Lock()
defer fake.mutex.Unlock()
fake.Stub = nil
Expand All @@ -124,7 +124,7 @@ func (fake *{{.Function.FakeName}}) ReturnsOnCall(i int, {{.Function.Returns.AsN
}
{{- end}}

func (fake *{{.Function.FakeName}}) Invocations() map[string][][]interface{} {
func (fake *{{.Name}}) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.mutex.RLock()
Expand Down
1 change: 0 additions & 1 deletion generator/generator_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
Expect(f.Package).NotTo(BeNil())
Expect(f.Methods).To(HaveLen(0))
Expect(f.Function.Name).To(Equal("HandlerFunc"))
Expect(f.Function.FakeName).To(Equal("FakeHandlerFunc"))
Expect(f.Function.Params).To(HaveLen(2))
Expect(f.Function.Returns).To(BeEmpty())
})
Expand Down
12 changes: 5 additions & 7 deletions generator/interface_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (f *Fake) addTypesForMethod(sig *types.Signature) {
}
}

func methodForSignature(sig *types.Signature, fakeName string, fakePackage string, methodName string, importsMap map[string]Import) Method {
func methodForSignature(sig *types.Signature, methodName string, importsMap map[string]Import) Method {
params := []Param{}
for i := 0; i < sig.Params().Len(); i++ {
param := sig.Params().At(i)
Expand All @@ -46,11 +46,9 @@ func methodForSignature(sig *types.Signature, fakeName string, fakePackage strin
returns = append(returns, r)
}
return Method{
FakeName: fakeName,
FakePackage: fakePackage,
Name: methodName,
Returns: returns,
Params: params,
Name: methodName,
Returns: returns,
Params: params,
}
}

Expand Down Expand Up @@ -100,7 +98,7 @@ func (f *Fake) loadMethods() {

importsMap := f.importsMap()
for i := range methods {
method := methodForSignature(methods[i].Signature, f.Name, f.TargetAlias, methods[i].Func.Name(), importsMap)
method := methodForSignature(methods[i].Signature, methods[i].Func.Name(), importsMap)
f.Methods = append(f.Methods, method)
}
}
12 changes: 6 additions & 6 deletions generator/interface_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type {{.Name}} struct {
}

{{range .Methods -}}
func (fake *{{.FakeName}}) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} {
func (fake *{{$.Name}}) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} {
{{- range .Params.Slices}}
var {{UnExport .Name}}Copy {{.Type}}
if {{UnExport .Name}} != nil {
Expand Down Expand Up @@ -81,20 +81,20 @@ func (fake *{{.FakeName}}) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Return
{{- end}}
}

func (fake *{{.FakeName}}) {{.Name}}CallCount() int {
func (fake *{{$.Name}}) {{.Name}}CallCount() int {
fake.{{UnExport .Name}}Mutex.RLock()
defer fake.{{UnExport .Name}}Mutex.RUnlock()
return len(fake.{{UnExport .Name}}ArgsForCall)
}

func (fake *{{.FakeName}}) {{.Name}}Calls(stub func({{.Params.AsArgs}}) {{.Returns.AsReturnSignature}}) {
func (fake *{{$.Name}}) {{.Name}}Calls(stub func({{.Params.AsArgs}}) {{.Returns.AsReturnSignature}}) {
fake.{{UnExport .Name}}Mutex.Lock()
defer fake.{{UnExport .Name}}Mutex.Unlock()
fake.{{.Name}}Stub = stub
}

{{if .Params.HasLength -}}
func (fake *{{.FakeName}}) {{.Name}}ArgsForCall(i int) {{.Params.AsReturnSignature}} {
func (fake *{{$.Name}}) {{.Name}}ArgsForCall(i int) {{.Params.AsReturnSignature}} {
fake.{{UnExport .Name}}Mutex.RLock()
defer fake.{{UnExport .Name}}Mutex.RUnlock()
argsForCall := fake.{{UnExport .Name}}ArgsForCall[i]
Expand All @@ -103,7 +103,7 @@ func (fake *{{.FakeName}}) {{.Name}}ArgsForCall(i int) {{.Params.AsReturnSignatu
{{- end}}

{{if .Returns.HasLength -}}
func (fake *{{.FakeName}}) {{.Name}}Returns({{.Returns.AsNamedArgsWithTypes}}) {
func (fake *{{$.Name}}) {{.Name}}Returns({{.Returns.AsNamedArgsWithTypes}}) {
fake.{{UnExport .Name}}Mutex.Lock()
defer fake.{{UnExport .Name}}Mutex.Unlock()
fake.{{.Name}}Stub = nil
Expand All @@ -114,7 +114,7 @@ func (fake *{{.FakeName}}) {{.Name}}Returns({{.Returns.AsNamedArgsWithTypes}}) {
}{ {{- .Returns.AsNamedArgs -}} }
}

func (fake *{{.FakeName}}) {{.Name}}ReturnsOnCall(i int, {{.Returns.AsNamedArgsWithTypes}}) {
func (fake *{{$.Name}}) {{.Name}}ReturnsOnCall(i int, {{.Returns.AsNamedArgsWithTypes}}) {
fake.{{UnExport .Name}}Mutex.Lock()
defer fake.{{UnExport .Name}}Mutex.Unlock()
fake.{{.Name}}Stub = nil
Expand Down
4 changes: 2 additions & 2 deletions generator/package_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type {{.Name}} interface {
type {{.Name}}Shim struct {}

{{- range .Methods}}
func (p *{{.FakeName}}Shim) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} {
{{if .Returns.HasLength}}return {{end}}{{.FakePackage}}.{{.Name}}({{.Params.AsNamedArgsForInvocation}})
func (p *{{$.Name}}Shim) {{.Name}}({{.Params.AsNamedArgsWithTypes}}) {{.Returns.AsReturnSignature}} {
{{if .Returns.HasLength}}return {{end}}{{$.TargetAlias}}.{{.Name}}({{.Params.AsNamedArgsForInvocation}})
}
{{end}}
var _ {{.Name}} = new({{.Name}}Shim)
Expand Down