Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Fitzgerald <[email protected]>
  • Loading branch information
joefitzgerald committed Dec 18, 2024
1 parent 1db6bf1 commit 8f0d484
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions generator/generator_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
Expect(f.Packages).NotTo(BeNil())
Expect(f.Package).NotTo(BeNil())
Expect(f.Methods).To(HaveLen(6))
Expect(f.GenericTypeParametersAndConstraints).To(BeEmpty())
Expect(f.GenericTypeParameters).To(BeEmpty())
Expect(f.GenericTypeConstraints).To(BeEmpty())
})
})

Expand Down Expand Up @@ -128,6 +131,28 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
Expect(f.Function.Returns).To(BeEmpty())
})
})

when("the target is an interface with generic methods", func() {
it("succeeds", func() {
c := &Cache{}
f, err = NewFake(InterfaceOrFunction, "GenericInterface", "github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface", "FakeGenericInterface", "genericinterfacefakes", "", "", c)
Expect(err).NotTo(HaveOccurred())
Expect(f).NotTo(BeNil())
Expect(f.TargetAlias).To(Equal("genericinterface"))
Expect(f.TargetName).To(Equal("GenericInterface"))
Expect(f.TargetPackage).To(Equal("github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericinterface"))
Expect(f.Name).To(Equal("FakeGenericInterface"))
Expect(f.Mode).To(Equal(InterfaceOrFunction))
Expect(f.DestinationPackage).To(Equal("genericinterfacefakes"))
Expect(f.Function).To(BeZero())
Expect(f.Packages).NotTo(BeNil())
Expect(f.Package).NotTo(BeNil())
Expect(f.Methods).To(HaveLen(4))
Expect(f.GenericTypeParametersAndConstraints).To(Equal("[T genericinterface.CustomTypeT]"))
Expect(f.GenericTypeParameters).To(Equal("[T]"))
Expect(f.GenericTypeConstraints).To(Equal("[genericinterface.CustomTypeT]"))
})
})
})

when("manually constructing a fake", func() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ require (

go 1.23

toolchain go1.23.1
toolchain go1.23.4

0 comments on commit 8f0d484

Please sign in to comment.