Skip to content

Commit

Permalink
[CHANGED]: apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jfragosoperez committed Nov 13, 2024
1 parent ba9924e commit 252ef3c
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 103 deletions.
8 changes: 8 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ packages:
filename: "mock_{{.InterfaceName}}_test.go"
inpackage: True
keeptree: False
github.com/vektra/mockery/v2/pkg/fixtures/iface_typed_param:
config:
all: True
dir: "{{.InterfaceDir}}"
mockname: "{{.InterfaceName}}"
outpkg: "{{.PackageName}}_test"
filename: "{{.InterfaceNameSnake}}_mock_test.go"
keeptree: True

This file was deleted.

7 changes: 7 additions & 0 deletions pkg/fixtures/iface_typed_param/getter_iface_typed_param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package iface_typed_param

import "io"

type GetterIfaceTypedParam[T io.Reader] interface {
Get() T
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions pkg/fixtures/iface_typed_param/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package iface_typed_param_test

import (
"bufio"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIfaceWithIfaceTypedParamReturnValues(t *testing.T) {
t.Parallel()

tests := []struct {
name string
returnVal *bufio.Reader
}{
{"nil return val", nil},
{"returning val", bufio.NewReader(http.NoBody)},
}
for _, test := range tests {
t.Run(test.name, func(st *testing.T) {
m := NewGetterIfaceTypedParam[*bufio.Reader](st)
m.EXPECT().Get().Return(test.returnVal)

assert.Equal(st, test.returnVal, m.Get())
})
}
}
4 changes: 0 additions & 4 deletions pkg/fixtures/requester_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ import "io"
type RequesterIface interface {
Get() io.Reader
}

type RequesterIfaceWithInterfaceTypedParam[T io.Reader] interface {
Get() T
}
16 changes: 0 additions & 16 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,22 +337,6 @@ func (s *GeneratorSuite) TestGeneratorChecksInterfacesForNilable() {
s.checkGeneration("requester_iface.go", "RequesterIface", false, "", "")
}

func (s *GeneratorSuite) TestGeneratorChecksInterfacesWithGenericInterfaceTypedParamForNilable() {
expectedBytes, err := os.ReadFile(getMocksPath("RequesterIfaceWithInterfaceTypedParam.go"))
s.Require().NoError(err)

expected := string(expectedBytes)
expected = expected[strings.Index(expected, "// RequesterIfaceWithInterfaceTypedParam is"):]

cfg := GeneratorConfig{
StructName: "RequesterIfaceWithInterfaceTypedParam",
WithExpecter: true,
UnrollVariadic: false,
}

s.checkGenerationWithConfig("requester_iface.go", "RequesterIfaceWithInterfaceTypedParam", cfg, expected)
}

func (s *GeneratorSuite) TestGeneratorTreatsAnyAsNilable() {
cfg := GeneratorConfig{
WithExpecter: true,
Expand Down

0 comments on commit 252ef3c

Please sign in to comment.