Skip to content

Commit

Permalink
migrate to new Mockery config (#5684)
Browse files Browse the repository at this point in the history
Closes #5564.

Signed-off-by: Harshil Patel <harshilpatel1973@gmail.com>
  • Loading branch information
harshil1973 authored Aug 21, 2023
1 parent 0b1d23c commit 55d98f7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
26 changes: 26 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
with-expecter: False
mockname: "{{.InterfaceName}}"
filename: "{{.InterfaceNameSnake}}.go"
outpkg: "mocks"
dir: '{{trimPrefix .PackagePath "github.com/projectcontour/contour/" }}/mocks'
disable-version-string: True
packages:
sigs.k8s.io/controller-runtime/pkg/manager:
config:
dir: "internal/controller/mocks"
interfaces:
Manager:
github.com/projectcontour/contour/internal/debug:
interfaces:
DagBuilder:
github.com/projectcontour/contour/internal/k8s:
interfaces:
StatusMetrics:
sigs.k8s.io/controller-runtime/pkg/cache:
config:
dir: "internal/k8s/mocks"
interfaces:
Cache:
github.com/projectcontour/contour/internal/leadership:
interfaces:
NeedLeaderElectionNotification:
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ generate-metrics-docs:
.PHONY: generate-go
generate-go:
@echo "Generating mocks..."
@go generate ./...
@go run github.com/vektra/mockery/v2

.PHONY: check-generate
check-generate: generate
Expand Down
2 changes: 0 additions & 2 deletions internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

//go:generate go run github.com/vektra/mockery/v2 --case=snake --name=Manager --srcpkg=sigs.k8s.io/controller-runtime/pkg/manager --disable-version-string

func TestRegisterControllers(t *testing.T) {
tests := map[string]func(*mocks.Manager) error{
"gateway controller": func(mockManager *mocks.Manager) error {
Expand Down
2 changes: 0 additions & 2 deletions internal/debug/dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

//go:generate go run github.com/vektra/mockery/v2 --case=snake --name=DagBuilder --srcpkg=github.com/projectcontour/contour/internal/debug --disable-version-string

func TestWriteDotEscapesLabels(t *testing.T) {
d := dag.DAG{
Listeners: map[string]*dag.Listener{},
Expand Down
2 changes: 0 additions & 2 deletions internal/k8s/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

//go:generate go run github.com/vektra/mockery/v2 --case=snake --name=StatusMetrics --disable-version-string

func TestStatusUpdateHandlerRequiresLeaderElection(t *testing.T) {
var s manager.LeaderElectionRunnable = &StatusUpdateHandler{}
require.True(t, s.NeedLeaderElection())
Expand Down
1 change: 0 additions & 1 deletion internal/k8s/statusaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func TestStatusAddressUpdater(t *testing.T) {
}
}

//go:generate go run github.com/vektra/mockery/v2 --case=snake --name=Cache --srcpkg=sigs.k8s.io/controller-runtime/pkg/cache --disable-version-string
func TestStatusAddressUpdater_Gateway(t *testing.T) {
log := fixture.NewTestLogger(t)
log.SetLevel(logrus.DebugLevel)
Expand Down
2 changes: 0 additions & 2 deletions internal/leadership/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

//go:generate go run github.com/vektra/mockery/v2 --case=snake --name=NeedLeaderElectionNotification --disable-version-string

func TestNotifier(t *testing.T) {
toNotify1 := &mocks.NeedLeaderElectionNotification{}
toNotify1.On("OnElectedLeader").Once()
Expand Down

0 comments on commit 55d98f7

Please sign in to comment.