From ce27345b0523998251af23c6803328e7c7909cd8 Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Fri, 11 Aug 2023 21:27:18 +0200 Subject: [PATCH] feat: Migrating mock library Signed-off-by: Vincent Boutour --- Makefile | 2 +- go.mod | 1 + go.sum | 2 ++ pkg/middleware/middleware_test.go | 2 +- pkg/mocks/database.go | 2 +- pkg/mocks/interfaces.go | 2 +- pkg/mocks/pgx.go | 2 +- pkg/notifier/notifier_test.go | 2 +- pkg/notifier/releases_test.go | 2 +- pkg/service/ketchup/ketchup_test.go | 2 +- pkg/service/repository/repository_test.go | 2 +- pkg/service/user/user_test.go | 2 +- pkg/store/ketchup/ketchup_test.go | 2 +- pkg/store/repository/repository_test.go | 2 +- pkg/store/repository/repository_version_test.go | 2 +- pkg/store/user/user_test.go | 2 +- 16 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index fa5238c1..88a34440 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,6 @@ dev: format style test build .PHONY: init init: @curl --disable --silent --show-error --location --max-time 30 "https://raw.githubusercontent.com/ViBiOh/scripts/main/bootstrap" | bash -s -- "-c" "git_hooks" "coverage" "release" - go install "github.com/golang/mock/mockgen@v1.6.0" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@latest" go install "golang.org/x/tools/cmd/goimports@latest" go install "golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@master" @@ -77,6 +76,7 @@ style: ## mocks: Generate mocks .PHONY: mocks mocks: + go install "go.uber.org/mock/mockgen@latest" find . -name "mocks" -type d -exec rm -r "{}" \+ go generate -run mockgen $(PACKAGES) mockgen -destination pkg/mocks/pgx.go -package mocks -mock_names Row=Row,Rows=Rows github.com/jackc/pgx/v5 Row,Rows diff --git a/go.mod b/go.mod index 9187c3ac..663f5ab1 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/jackc/pgx/v5 v5.4.3 github.com/prometheus/client_golang v1.16.0 go.opentelemetry.io/otel/trace v1.16.0 + go.uber.org/mock v0.2.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index df162160..f4b8ea72 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,8 @@ go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lI go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= +go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= diff --git a/pkg/middleware/middleware_test.go b/pkg/middleware/middleware_test.go index 3a4c5440..64f4a9bd 100644 --- a/pkg/middleware/middleware_test.go +++ b/pkg/middleware/middleware_test.go @@ -10,7 +10,7 @@ import ( "github.com/ViBiOh/httputils/v4/pkg/request" "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestMiddleware(t *testing.T) { diff --git a/pkg/mocks/database.go b/pkg/mocks/database.go index c5d47e56..9aedd810 100644 --- a/pkg/mocks/database.go +++ b/pkg/mocks/database.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" pgx "github.com/jackc/pgx/v5" + gomock "go.uber.org/mock/gomock" ) // Database is a mock of Database interface. diff --git a/pkg/mocks/interfaces.go b/pkg/mocks/interfaces.go index 00dbd665..09ec7112 100644 --- a/pkg/mocks/interfaces.go +++ b/pkg/mocks/interfaces.go @@ -12,7 +12,7 @@ import ( model0 "github.com/ViBiOh/ketchup/pkg/model" semver "github.com/ViBiOh/ketchup/pkg/semver" model1 "github.com/ViBiOh/mailer/pkg/model" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // Mailer is a mock of Mailer interface. diff --git a/pkg/mocks/pgx.go b/pkg/mocks/pgx.go index b3243ed5..5f7d7965 100644 --- a/pkg/mocks/pgx.go +++ b/pkg/mocks/pgx.go @@ -7,9 +7,9 @@ package mocks import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" pgx "github.com/jackc/pgx/v5" pgconn "github.com/jackc/pgx/v5/pgconn" + gomock "go.uber.org/mock/gomock" ) // Row is a mock of Row interface. diff --git a/pkg/notifier/notifier_test.go b/pkg/notifier/notifier_test.go index fdb8b990..12337eb9 100644 --- a/pkg/notifier/notifier_test.go +++ b/pkg/notifier/notifier_test.go @@ -14,7 +14,7 @@ import ( "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" "github.com/ViBiOh/ketchup/pkg/semver" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/notifier/releases_test.go b/pkg/notifier/releases_test.go index ecb8f1cd..09cc0a13 100644 --- a/pkg/notifier/releases_test.go +++ b/pkg/notifier/releases_test.go @@ -11,7 +11,7 @@ import ( "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" "github.com/ViBiOh/ketchup/pkg/semver" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestGetNewStandardReleases(t *testing.T) { diff --git a/pkg/service/ketchup/ketchup_test.go b/pkg/service/ketchup/ketchup_test.go index acf7e271..25fcc8d6 100644 --- a/pkg/service/ketchup/ketchup_test.go +++ b/pkg/service/ketchup/ketchup_test.go @@ -11,7 +11,7 @@ import ( httpModel "github.com/ViBiOh/httputils/v4/pkg/model" "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/service/repository/repository_test.go b/pkg/service/repository/repository_test.go index be1acd0b..5ae5abad 100644 --- a/pkg/service/repository/repository_test.go +++ b/pkg/service/repository/repository_test.go @@ -12,7 +12,7 @@ import ( "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" "github.com/ViBiOh/ketchup/pkg/semver" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/service/user/user_test.go b/pkg/service/user/user_test.go index 6554e919..8a9dc5fe 100644 --- a/pkg/service/user/user_test.go +++ b/pkg/service/user/user_test.go @@ -11,7 +11,7 @@ import ( httpModel "github.com/ViBiOh/httputils/v4/pkg/model" "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/store/ketchup/ketchup_test.go b/pkg/store/ketchup/ketchup_test.go index 05751f06..b71a8798 100644 --- a/pkg/store/ketchup/ketchup_test.go +++ b/pkg/store/ketchup/ketchup_test.go @@ -10,8 +10,8 @@ import ( authModel "github.com/ViBiOh/auth/v2/pkg/model" "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" "github.com/jackc/pgx/v5" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/store/repository/repository_test.go b/pkg/store/repository/repository_test.go index 4d197dc5..df1418a4 100644 --- a/pkg/store/repository/repository_test.go +++ b/pkg/store/repository/repository_test.go @@ -9,8 +9,8 @@ import ( "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" "github.com/jackc/pgx/v5" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/store/repository/repository_version_test.go b/pkg/store/repository/repository_version_test.go index d9a63b0e..c155c868 100644 --- a/pkg/store/repository/repository_version_test.go +++ b/pkg/store/repository/repository_version_test.go @@ -7,8 +7,8 @@ import ( "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" "github.com/jackc/pgx/v5" + "go.uber.org/mock/gomock" ) var errFailed = errors.New("timeout") diff --git a/pkg/store/user/user_test.go b/pkg/store/user/user_test.go index be670d04..ec9b19d9 100644 --- a/pkg/store/user/user_test.go +++ b/pkg/store/user/user_test.go @@ -9,8 +9,8 @@ import ( authModel "github.com/ViBiOh/auth/v2/pkg/model" "github.com/ViBiOh/ketchup/pkg/mocks" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/golang/mock/gomock" "github.com/jackc/pgx/v5" + "go.uber.org/mock/gomock" ) var testEmail = "nobody@localhost"