Skip to content

Commit 365b8eb

Browse files
committed
shuffling around
1 parent 705aec3 commit 365b8eb

9 files changed

+24
-29
lines changed

internal/template_generator.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/chigopher/pathlib"
1717
"github.com/rs/zerolog"
1818
"github.com/vektra/mockery/v3/internal/stackerr"
19-
"github.com/vektra/mockery/v3/registry"
2019
"github.com/vektra/mockery/v3/template"
2120
"golang.org/x/tools/go/packages"
2221
"golang.org/x/tools/imports"
@@ -101,7 +100,7 @@ func findPkgPath(dirPath *pathlib.Path) (string, error) {
101100

102101
type TemplateGenerator struct {
103102
templateName string
104-
registry *registry.Registry
103+
registry *template.Registry
105104
formatter Formatter
106105
pkgConfig *Config
107106
inPackage bool
@@ -148,7 +147,7 @@ func NewTemplateGenerator(
148147
log.Debug().Msg("output package detected to not be in-package of original package")
149148
}
150149

151-
reg, err := registry.New(srcPkg, outPkgPath, inPackage)
150+
reg, err := template.NewRegistry(srcPkg, outPkgPath, inPackage)
152151
if err != nil {
153152
return nil, fmt.Errorf("creating new registry: %w", err)
154153
}

mockery-tools.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=v3.0.0-alpha.11
1+
VERSION=v3.0.0-alpha.12

registry/method_scope.go renamed to template/method_scope.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package registry
1+
package template
22

33
import (
44
"context"

registry/package.go renamed to template/package.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package registry
1+
package template
22

33
import (
44
"strings"

registry/registry.go renamed to template/registry.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package registry
1+
package template
22

33
import (
44
"context"
@@ -33,7 +33,7 @@ type Registry struct {
3333

3434
// New loads the source package info and returns a new instance of
3535
// Registry.
36-
func New(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) {
36+
func NewRegistry(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) {
3737
return &Registry{
3838
dstPkgPath: dstPkgPath,
3939
srcPkg: srcPkg,

template/template.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"text/template"
1010

1111
"github.com/huandu/xstrings"
12-
"github.com/vektra/mockery/v3/registry"
1312
)
1413

1514
// Template is the Moq template. It is capable of generating the Moq
@@ -63,13 +62,13 @@ func exported(s string) string {
6362
}
6463

6564
var TemplateMockFuncs = template.FuncMap{
66-
"importStatement": func(imprt *registry.Package) string {
65+
"importStatement": func(imprt *Package) string {
6766
if imprt.Alias == "" {
6867
return `"` + imprt.Path() + `"`
6968
}
7069
return imprt.Alias + ` "` + imprt.Path() + `"`
7170
},
72-
"syncPkgQualifier": func(imports []*registry.Package) string {
71+
"syncPkgQualifier": func(imports []*Package) string {
7372
for _, imprt := range imports {
7473
if imprt.Path() == "sync" {
7574
return imprt.Qualifier()

template/template_data.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"fmt"
55
"go/types"
66
"strings"
7-
8-
"github.com/vektra/mockery/v3/registry"
97
)
108

9+
// ConfigData is the data sent to the template for the config file.
1110
type ConfigData struct {
1211
ConfigDir string
1312
InterfaceDir string
@@ -20,13 +19,13 @@ type ConfigData struct {
2019
SrcPackagePath string
2120
}
2221

23-
// Data is the template data used to render the Moq template.
22+
// Data is the template data used to render the mock template.
2423
type Data struct {
2524
Boilerplate string
2625
BuildTags string
2726
PkgName string
2827
SrcPkgQualifier string
29-
Imports []*registry.Package
28+
Imports []*Package
3029
Mocks []MockData
3130
TemplateData map[string]any
3231
}
@@ -98,7 +97,7 @@ type MethodData struct {
9897
// Scope represents the lexical scope of the method. Its primary function
9998
// is keeping track of all names visible in the current scope, which allows
10099
// the creation of new variables with guaranteed non-conflicting names.
101-
Scope *registry.MethodScope
100+
Scope *MethodScope
102101
}
103102

104103
// ArgList is the string representation of method parameters, ex:
@@ -217,7 +216,7 @@ type TypeParamData struct {
217216
// ParamData is the data which represents a parameter to some method of
218217
// an interface.
219218
type ParamData struct {
220-
Var *registry.Var
219+
Var *Var
221220
Variadic bool
222221
}
223222

template/template_test.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package template
33
import (
44
"go/types"
55
"testing"
6-
7-
"github.com/vektra/mockery/v3/registry"
86
)
97

108
func TestTemplateMockFuncs(t *testing.T) {
@@ -19,8 +17,8 @@ func TestTemplateMockFuncs(t *testing.T) {
1917
})
2018

2119
t.Run("ImportStatement", func(t *testing.T) {
22-
f := TemplateMockFuncs["ImportStatement"].(func(*registry.Package) string)
23-
pkg := registry.NewPackage(types.NewPackage("xyz", "xyz"))
20+
f := TemplateMockFuncs["ImportStatement"].(func(*Package) string)
21+
pkg := NewPackage(types.NewPackage("xyz", "xyz"))
2422
if f(pkg) != `"xyz"` {
2523
t.Errorf("ImportStatement(...): want: `\"xyz\"`; got: `%s`", f(pkg))
2624
}
@@ -32,22 +30,22 @@ func TestTemplateMockFuncs(t *testing.T) {
3230
})
3331

3432
t.Run("SyncPkgQualifier", func(t *testing.T) {
35-
f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*registry.Package) string)
33+
f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*Package) string)
3634
if f(nil) != "sync" {
3735
t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(nil))
3836
}
39-
imports := []*registry.Package{
40-
registry.NewPackage(types.NewPackage("sync", "sync")),
41-
registry.NewPackage(types.NewPackage("github.com/some/module", "module")),
37+
imports := []*Package{
38+
NewPackage(types.NewPackage("sync", "sync")),
39+
NewPackage(types.NewPackage("github.com/some/module", "module")),
4240
}
4341
if f(imports) != "sync" {
4442
t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(imports))
4543
}
4644

47-
syncPkg := registry.NewPackage(types.NewPackage("sync", "sync"))
45+
syncPkg := NewPackage(types.NewPackage("sync", "sync"))
4846
syncPkg.Alias = "stdsync"
49-
otherSyncPkg := registry.NewPackage(types.NewPackage("github.com/someother/sync", "sync"))
50-
imports = []*registry.Package{otherSyncPkg, syncPkg}
47+
otherSyncPkg := NewPackage(types.NewPackage("github.com/someother/sync", "sync"))
48+
imports = []*Package{otherSyncPkg, syncPkg}
5149
if f(imports) != "stdsync" {
5250
t.Errorf("SyncPkgQualifier(...): want: `stdsync`; got: `%s`", f(imports))
5351
}

registry/var.go renamed to template/var.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package registry
1+
package template
22

33
import (
44
"go/types"

0 commit comments

Comments
 (0)