From 0002986116a83b2f9f2ebb3d7b8e85a0cd0597e7 Mon Sep 17 00:00:00 2001 From: Joe Fitzgerald Date: Thu, 1 Apr 2021 11:54:16 -0600 Subject: [PATCH] attempt to reproduce #174 - seems to work as expected --- fixtures/externalpkg/aliased_interface.go | 4 ++ .../externalpkgfakes/fake_context.go | 67 +++++++++++++++++++ fixtures/internalpkg/aliased_interface.go | 8 +++ .../internal/internal_interface.go | 5 ++ .../internalpkgfakes/fake_context.go | 67 +++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 fixtures/externalpkg/aliased_interface.go create mode 100644 fixtures/externalpkg/externalpkgfakes/fake_context.go create mode 100644 fixtures/internalpkg/aliased_interface.go create mode 100644 fixtures/internalpkg/internal/internal_interface.go create mode 100644 fixtures/internalpkg/internalpkgfakes/fake_context.go diff --git a/fixtures/externalpkg/aliased_interface.go b/fixtures/externalpkg/aliased_interface.go new file mode 100644 index 0000000..bed5af3 --- /dev/null +++ b/fixtures/externalpkg/aliased_interface.go @@ -0,0 +1,4 @@ +package externalpkg + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate +//counterfeiter:generate github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg.Context diff --git a/fixtures/externalpkg/externalpkgfakes/fake_context.go b/fixtures/externalpkg/externalpkgfakes/fake_context.go new file mode 100644 index 0000000..eed8e4a --- /dev/null +++ b/fixtures/externalpkg/externalpkgfakes/fake_context.go @@ -0,0 +1,67 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package externalpkgfakes + +import ( + "sync" + + "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg" +) + +type FakeContext struct { + DoSomethingStub func() + doSomethingMutex sync.RWMutex + doSomethingArgsForCall []struct { + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *FakeContext) DoSomething() { + fake.doSomethingMutex.Lock() + fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { + }{}) + stub := fake.DoSomethingStub + fake.recordInvocation("DoSomething", []interface{}{}) + fake.doSomethingMutex.Unlock() + if stub != nil { + fake.DoSomethingStub() + } +} + +func (fake *FakeContext) DoSomethingCallCount() int { + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + return len(fake.doSomethingArgsForCall) +} + +func (fake *FakeContext) DoSomethingCalls(stub func()) { + fake.doSomethingMutex.Lock() + defer fake.doSomethingMutex.Unlock() + fake.DoSomethingStub = stub +} + +func (fake *FakeContext) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *FakeContext) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ internalpkg.Context = new(FakeContext) diff --git a/fixtures/internalpkg/aliased_interface.go b/fixtures/internalpkg/aliased_interface.go new file mode 100644 index 0000000..d58ccb5 --- /dev/null +++ b/fixtures/internalpkg/aliased_interface.go @@ -0,0 +1,8 @@ +package internalpkg + +import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg/internal" + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate +//counterfeiter:generate . Context + +type Context = internal.Context diff --git a/fixtures/internalpkg/internal/internal_interface.go b/fixtures/internalpkg/internal/internal_interface.go new file mode 100644 index 0000000..e58468e --- /dev/null +++ b/fixtures/internalpkg/internal/internal_interface.go @@ -0,0 +1,5 @@ +package internal + +type Context interface { + DoSomething() +} diff --git a/fixtures/internalpkg/internalpkgfakes/fake_context.go b/fixtures/internalpkg/internalpkgfakes/fake_context.go new file mode 100644 index 0000000..c122331 --- /dev/null +++ b/fixtures/internalpkg/internalpkgfakes/fake_context.go @@ -0,0 +1,67 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package internalpkgfakes + +import ( + "sync" + + "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/internalpkg" +) + +type FakeContext struct { + DoSomethingStub func() + doSomethingMutex sync.RWMutex + doSomethingArgsForCall []struct { + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *FakeContext) DoSomething() { + fake.doSomethingMutex.Lock() + fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { + }{}) + stub := fake.DoSomethingStub + fake.recordInvocation("DoSomething", []interface{}{}) + fake.doSomethingMutex.Unlock() + if stub != nil { + fake.DoSomethingStub() + } +} + +func (fake *FakeContext) DoSomethingCallCount() int { + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + return len(fake.doSomethingArgsForCall) +} + +func (fake *FakeContext) DoSomethingCalls(stub func()) { + fake.doSomethingMutex.Lock() + defer fake.doSomethingMutex.Unlock() + fake.DoSomethingStub = stub +} + +func (fake *FakeContext) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *FakeContext) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ internalpkg.Context = new(FakeContext)