From 3de382ded7399367bf62c63006cb47190fd2a4ea Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Jul 2019 16:39:18 +0100 Subject: [PATCH 1/5] Test fixture for an interface with methods taking inline structs --- fixtures/inlinestructs/interface.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 fixtures/inlinestructs/interface.go diff --git a/fixtures/inlinestructs/interface.go b/fixtures/inlinestructs/interface.go new file mode 100644 index 0000000..606466c --- /dev/null +++ b/fixtures/inlinestructs/interface.go @@ -0,0 +1,17 @@ +package inlinestructs + +import ( + "context" + "net/http" + "time" +) + +type SomeInterface interface { + DoSomething(ctx context.Context, body struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request + }) error +} From 8d6a9ce70649ef69f813dcccc1faf8cdfed533ab Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Jul 2019 16:39:38 +0100 Subject: [PATCH 2/5] Generating imports for struct types --- generator/loader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generator/loader.go b/generator/loader.go index 6d17dd3..325463f 100644 --- a/generator/loader.go +++ b/generator/loader.go @@ -131,6 +131,10 @@ func (f *Fake) addImportsFor(typ types.Type) { return case *types.Signature: f.addTypesForMethod(t) + case *types.Struct: + for i := 0; i < t.NumFields(); i++ { + f.addImportsFor(t.Field(i).Type()) + } default: log.Printf("!!! WARNING: Missing case for type %s\n", reflect.TypeOf(typ).String()) } From 48e3c3ce6b76542e796d9551a3c96068f411360e Mon Sep 17 00:00:00 2001 From: Chris H Date: Thu, 4 Jul 2019 17:07:53 +0100 Subject: [PATCH 3/5] Moving the inline interface with everything else --- .../{inlinestructs/interface.go => inline_struct_params.go} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename fixtures/{inlinestructs/interface.go => inline_struct_params.go} (82%) diff --git a/fixtures/inlinestructs/interface.go b/fixtures/inline_struct_params.go similarity index 82% rename from fixtures/inlinestructs/interface.go rename to fixtures/inline_struct_params.go index 606466c..7c8f117 100644 --- a/fixtures/inlinestructs/interface.go +++ b/fixtures/inline_struct_params.go @@ -1,4 +1,4 @@ -package inlinestructs +package fixtures import ( "context" @@ -6,7 +6,7 @@ import ( "time" ) -type SomeInterface interface { +type InlineInterface interface { DoSomething(ctx context.Context, body struct { SomeString string SomeStringPointer *string From a6be7a4b4d0674a2155da6008c19f2f79659dd69 Mon Sep 17 00:00:00 2001 From: Joe Fitzgerald Date: Sun, 7 Jul 2019 22:10:10 -0600 Subject: [PATCH 4/5] :arrow_up: dependencies, remove spurious test file --- go.mod | 11 +- go.sum | 27 ++-- integration/integration_test.go | 216 -------------------------------- 3 files changed, 28 insertions(+), 226 deletions(-) delete mode 100644 integration/integration_test.go diff --git a/go.mod b/go.mod index 6b43f7d..0573988 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,16 @@ module github.com/maxbrunsfeld/counterfeiter/v6 require ( + github.com/golang/protobuf v1.3.1 // indirect github.com/joefitzgerald/rainbow-reporter v0.1.0 + github.com/kr/pretty v0.1.0 // indirect + github.com/onsi/ginkgo v1.8.0 // indirect github.com/onsi/gomega v1.5.0 github.com/sclevine/spec v1.2.0 - golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect - golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2 // indirect + golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect + golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect golang.org/x/text v0.3.2 // indirect - golang.org/x/tools v0.0.0-20190601110225-0abef6e9ecb8 + golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index be1a9a1..b1fb1b0 100644 --- a/go.sum +++ b/go.sum @@ -2,12 +2,21 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/joefitzgerald/rainbow-reporter v0.1.0 h1:AuMG652zjdzI0YCCnXAqATtRBpGXMcAnrajcaTrSeuo= github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/sclevine/spec v1.2.0 h1:1Jwdf9jSfDl9NVmt8ndHqbTZ7XCCPbh1jI3hkDBHVYA= @@ -15,9 +24,9 @@ github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= @@ -25,20 +34,24 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2 h1:T5DasATyLQfmbTpfEXx/IOL9vfjzW6up+ZDkmHvIf2s= -golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190601110225-0abef6e9ecb8 h1:KFgOV120pDm8h0MBnt26wwMmwdhSXE+K+G9jg1ZjxbE= -golang.org/x/tools v0.0.0-20190601110225-0abef6e9ecb8/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeBz87XgHAQuj+TbimYJuiw= +golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/integration/integration_test.go b/integration/integration_test.go deleted file mode 100644 index a43b166..0000000 --- a/integration/integration_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package integration_test - -import ( - "bytes" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - - "testing" - - "github.com/onsi/gomega/gbytes" - "github.com/onsi/gomega/gexec" - - . "github.com/onsi/gomega" - "github.com/sclevine/spec" -) - -var ( - tmpDir string - pathToCounterfeiter string -) - -// func TestMain(m *testing.M) { -// var err error -// pathToCounterfeiter, err = gexec.Build("github.com/maxbrunsfeld/counterfeiter/v6") -// if err != nil { -// panic(err) -// } -// -// result := m.Run() -// gexec.CleanupBuildArtifacts() -// os.Exit(result) -// } - -// func TestCounterfeiter(t *testing.T) { -// spec.Run(t, "Counterfeiter", testCounterfeiter, spec.Report(reporter.Rainbow{})) -// } - -func testCounterfeiter(t *testing.T, when spec.G, it spec.S) { - var pathToCLI string - - tmpPath := func(destination string) string { - return filepath.Join(tmpDir, "src", destination) - } - - copyIn := func(fixture string, directory string) { - fixturesPath := filepath.Join(directory, "fixtures") - err := os.MkdirAll(fixturesPath, 0777) - Expect(err).ToNot(HaveOccurred()) - - filepath.Walk(filepath.Join("..", "fixtures", fixture), func(path string, info os.FileInfo, err error) error { - if info.IsDir() { - return nil - } - - base := filepath.Base(path) - - fileHandle, err := os.Open(path) - Expect(err).ToNot(HaveOccurred()) - defer fileHandle.Close() - - dst, err := os.Create(filepath.Join(fixturesPath, base)) - Expect(err).ToNot(HaveOccurred()) - defer dst.Close() - - _, err = io.Copy(dst, fileHandle) - Expect(err).ToNot(HaveOccurred()) - return nil - }) - } - - startCounterfeiter := func(workingDir string, fixtureName string, otherArgs ...string) *gexec.Session { - fakeGoPathDir := filepath.Dir(filepath.Dir(workingDir)) - absPath, _ := filepath.Abs(fakeGoPathDir) - absPathWithSymlinks, _ := filepath.EvalSymlinks(absPath) - - fixturePath := filepath.Join("fixtures", fixtureName) - args := append([]string{fixturePath}, otherArgs...) - cmd := exec.Command(pathToCounterfeiter, args...) - cmd.Dir = workingDir - cmd.Env = []string{"GOPATH=" + absPathWithSymlinks} - outWriter := &bytes.Buffer{} - errWriter := &bytes.Buffer{} - session, err := gexec.Start(cmd, outWriter, errWriter) - Expect(err).ToNot(HaveOccurred()) - return session - } - - startCounterfeiterWithoutFixture := func(workingDir string, args ...string) *gexec.Session { - fakeGoPathDir := filepath.Dir(filepath.Dir(workingDir)) - absPath, _ := filepath.Abs(fakeGoPathDir) - absPathWithSymlinks, _ := filepath.EvalSymlinks(absPath) - - cmd := exec.Command(pathToCounterfeiter, args...) - cmd.Dir = workingDir - cmd.Env = []string{ - "GOPATH=" + absPathWithSymlinks, - "GOROOT=" + os.Getenv("GOROOT"), - } - outWriter := &bytes.Buffer{} - errWriter := &bytes.Buffer{} - session, err := gexec.Start(cmd, outWriter, errWriter) - Expect(err).ToNot(HaveOccurred()) - return session - } - - it.Before(func() { - RegisterTestingT(t) - var err error - tmpDir, err = ioutil.TempDir("", "counterfeiter-integration") - Expect(err).ToNot(HaveOccurred()) - pathToCLI = tmpPath("counterfeiter") - }) - - it.After(func() { - if tmpDir != "" { - err := os.RemoveAll(tmpDir) - Expect(err).ToNot(HaveOccurred()) - } - }) - - it("can generate a fake for a typed function", func() { - copyIn("typed_function.go", pathToCLI) - - session := startCounterfeiter(pathToCLI, "typed_function.go", "SomethingFactory") - - Eventually(session).Should(gexec.Exit(0)) - Expect(session).To(gbytes.Say("Wrote `FakeSomethingFactory")) - - generatedFakePath := filepath.Join(pathToCLI, "fixtures", "fixturesfakes", "fake_something_factory.go") - Expect(generatedFakePath).To(BeARegularFile()) - - expectedOutputPath := "../fixtures/expected_output/fake_something_factory.example" - expectedContents, err := ioutil.ReadFile(expectedOutputPath) - Expect(err).ToNot(HaveOccurred()) - - actualContents, err := ioutil.ReadFile(generatedFakePath) - Expect(err).ToNot(HaveOccurred()) - - // assert file content matches what we expect - Expect(string(actualContents)).To(Equal(string(expectedContents))) - }) - - it("can generate a fake for a internal interface, on a provided path", func() { - os.MkdirAll(filepath.Join(pathToCLI, "src", "counterfeiter"), 0777) - - session := startCounterfeiterWithoutFixture(pathToCLI, "-o", pathToCLI+"/custom/fake_write_closer.go", "io.WriteCloser") - Eventually(session).Should(gexec.Exit(0)) - Expect(session).To(gbytes.Say("Wrote `FakeWriteCloser`")) - - generatedFakePath := filepath.Join(pathToCLI, "custom", "fake_write_closer.go") - Expect(generatedFakePath).To(BeARegularFile()) - - expectedOutputPath := "../fixtures/expected_output/fake_write_closer.example" - expectedContents, err := ioutil.ReadFile(expectedOutputPath) - Expect(err).ToNot(HaveOccurred()) - - actualContents, err := ioutil.ReadFile(generatedFakePath) - Expect(err).ToNot(HaveOccurred()) - - // assert file content matches what we expect - Expect(string(actualContents)).To(Equal(string(expectedContents))) - }) - - when("when given a single argument", func() { - it.Before(func() { - copyIn("other_types.go", pathToCLI) - copyIn("something.go", tmpPath("otherrepo.com")) - }) - - it("writes a fake for the fully qualified interface that is provided in the argument", func() { - session := startCounterfeiterWithoutFixture(pathToCLI, "otherrepo.com/fixtures.Something") - - Eventually(session).Should(gexec.Exit(0)) - output := string(session.Out.Contents()) - - Expect(output).To(ContainSubstring("Wrote `FakeSomething`")) - }) - }) - - when("when given two arguments", func() { - it.Before(func() { - copyIn("something.go", pathToCLI) - }) - - it("writes a fake for the given interface from the provided file", func() { - session := startCounterfeiter(pathToCLI, "something.go", "Something") - - Eventually(session).Should(gexec.Exit(0)) - output := string(session.Out.Contents()) - - Expect(output).To(ContainSubstring("Wrote `FakeSomething`")) - }) - }) - - when("when provided three arguments", func() { - it.Before(func() { - copyIn("something.go", pathToCLI) - }) - - it("writes the fake to stdout", func() { - session := startCounterfeiter(pathToCLI, "something.go", "Something", "-") - - Eventually(session).Should(gexec.Exit(0)) - stdout := string(session.Out.Contents()) - stderr := string(session.Err.Contents()) - - Expect(stdout).To(ContainSubstring("// Code generated by counterfeiter. DO NOT EDIT.")) - Expect(stdout).NotTo(ContainSubstring("Wrote `FakeSomething")) - - Expect(stderr).To(ContainSubstring("Wrote `FakeSomething")) - }) - }) -} From e8250336a23688f78f496c7831ff8d7aa2636535 Mon Sep 17 00:00:00 2001 From: Joe Fitzgerald Date: Sun, 7 Jul 2019 22:19:38 -0600 Subject: [PATCH 5/5] add integration test, commit new fake --- .../fake_inline_struct_params.go | 151 ++++++++++++++++++ fixtures/inline_struct_params.go | 3 +- integration/roundtrip_test.go | 1 + 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 fixtures/fixturesfakes/fake_inline_struct_params.go diff --git a/fixtures/fixturesfakes/fake_inline_struct_params.go b/fixtures/fixturesfakes/fake_inline_struct_params.go new file mode 100644 index 0000000..dd383df --- /dev/null +++ b/fixtures/fixturesfakes/fake_inline_struct_params.go @@ -0,0 +1,151 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fixturesfakes + +import ( + "context" + "net/http" + "sync" + "time" + + "github.com/maxbrunsfeld/counterfeiter/v6/fixtures" +) + +type FakeInlineStructParams struct { + DoSomethingStub func(context.Context, struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request + }) error + doSomethingMutex sync.RWMutex + doSomethingArgsForCall []struct { + arg1 context.Context + arg2 struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request + } + } + doSomethingReturns struct { + result1 error + } + doSomethingReturnsOnCall map[int]struct { + result1 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *FakeInlineStructParams) DoSomething(arg1 context.Context, arg2 struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request +}) error { + fake.doSomethingMutex.Lock() + ret, specificReturn := fake.doSomethingReturnsOnCall[len(fake.doSomethingArgsForCall)] + fake.doSomethingArgsForCall = append(fake.doSomethingArgsForCall, struct { + arg1 context.Context + arg2 struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request + } + }{arg1, arg2}) + fake.recordInvocation("DoSomething", []interface{}{arg1, arg2}) + fake.doSomethingMutex.Unlock() + if fake.DoSomethingStub != nil { + return fake.DoSomethingStub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + fakeReturns := fake.doSomethingReturns + return fakeReturns.result1 +} + +func (fake *FakeInlineStructParams) DoSomethingCallCount() int { + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + return len(fake.doSomethingArgsForCall) +} + +func (fake *FakeInlineStructParams) DoSomethingCalls(stub func(context.Context, struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request +}) error) { + fake.doSomethingMutex.Lock() + defer fake.doSomethingMutex.Unlock() + fake.DoSomethingStub = stub +} + +func (fake *FakeInlineStructParams) DoSomethingArgsForCall(i int) (context.Context, struct { + SomeString string + SomeStringPointer *string + SomeTime time.Time + SomeTimePointer *time.Time + HTTPRequest http.Request +}) { + fake.doSomethingMutex.RLock() + defer fake.doSomethingMutex.RUnlock() + argsForCall := fake.doSomethingArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *FakeInlineStructParams) DoSomethingReturns(result1 error) { + fake.doSomethingMutex.Lock() + defer fake.doSomethingMutex.Unlock() + fake.DoSomethingStub = nil + fake.doSomethingReturns = struct { + result1 error + }{result1} +} + +func (fake *FakeInlineStructParams) DoSomethingReturnsOnCall(i int, result1 error) { + fake.doSomethingMutex.Lock() + defer fake.doSomethingMutex.Unlock() + fake.DoSomethingStub = nil + if fake.doSomethingReturnsOnCall == nil { + fake.doSomethingReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.doSomethingReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *FakeInlineStructParams) 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 *FakeInlineStructParams) 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 _ fixtures.InlineStructParams = new(FakeInlineStructParams) diff --git a/fixtures/inline_struct_params.go b/fixtures/inline_struct_params.go index 7c8f117..395a8b7 100644 --- a/fixtures/inline_struct_params.go +++ b/fixtures/inline_struct_params.go @@ -6,7 +6,8 @@ import ( "time" ) -type InlineInterface interface { +//counterfeiter:generate . InlineStructParams +type InlineStructParams interface { DoSomething(ctx context.Context, body struct { SomeString string SomeStringPointer *string diff --git a/integration/roundtrip_test.go b/integration/roundtrip_test.go index 1135f36..847dbfe 100644 --- a/integration/roundtrip_test.go +++ b/integration/roundtrip_test.go @@ -192,6 +192,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) { t("ImportsGoHyphenPackage", "imports_go_hyphen_package.go", "", filepath.Join("go-hyphenpackage", "fixture.go")) t("FirstInterface", "multiple_interfaces.go", "") t("SecondInterface", "multiple_interfaces.go", "") + t("InlineStructParams", "inline_struct_params.go", "") t("RequestFactory", "request_factory.go", "") t("ReusesArgTypes", "reuses_arg_types.go", "") t("SomethingWithForeignInterface", "something_remote.go", "", filepath.Join("aliased_package", "in_aliased_package.go"))