Skip to content

Commit

Permalink
add integration test to validate type aliases are treated correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Fitzgerald <joe@wearemomentum.ai>
  • Loading branch information
joefitzgerald committed Oct 10, 2024
1 parent ac22042 commit 241cc37
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fixtures/dup_packages/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages

go 1.12
go 1.22
5 changes: 5 additions & 0 deletions fixtures/type_aliases/extra/m.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package extra // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra"

import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra/primitive"

type M = primitive.M
3 changes: 3 additions & 0 deletions fixtures/type_aliases/extra/primitive/m.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package primitive // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/primitive"

type M map[string]interface{}
3 changes: 3 additions & 0 deletions fixtures/type_aliases/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases

go 1.22
14 changes: 14 additions & 0 deletions fixtures/type_aliases/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package type_aliases // import "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases"

import (
"context"

"github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra"
)

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

//counterfeiter:generate . WithAliasedType
type WithAliasedType interface {
FindExample(ctx context.Context, filter extra.M) ([]string, error)
}
19 changes: 19 additions & 0 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ func runTests(t *testing.T, when spec.G, it spec.S) {
})
})

when("generating interfaces using type aliases", func() {
it.Before(func() {
relativeDir = filepath.Join(relativeDir, "type_aliases")
copyDirFunc()
})
it("imports the aliased type, not the underlying type", func() {
cache := &generator.FakeCache{}
pkgPath := "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases"
interfaceName := "WithAliasedType"
fakePackageName := "type_aliasesfakes"
f, err := generator.NewFake(generator.InterfaceOrFunction, interfaceName, pkgPath, "Fake"+interfaceName, fakePackageName, "", baseDir, cache)
Expect(err).NotTo(HaveOccurred())
b, err := f.Generate(false)
Expect(err).NotTo(HaveOccurred())
Expect(string(b)).NotTo(ContainSubstring("primitive"))
Expect(string(b)).To(ContainSubstring(`"github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases/extra"`))
})
})

when(name, func() {
t := func(interfaceName string, filename string, subDir string, files ...string) {
when("working with "+filename, func() {
Expand Down

0 comments on commit 241cc37

Please sign in to comment.