diff --git a/.github/workflows/auto_mockgen.yml b/.github/workflows/auto_mockgen.yml index 1212e5c..fdbadc4 100644 --- a/.github/workflows/auto_mockgen.yml +++ b/.github/workflows/auto_mockgen.yml @@ -11,6 +11,8 @@ jobs: generate: runs-on: ubuntu-latest + env: + EXAMPLE_TESTS_ROOT: ${{ github.workspace }} steps: - uses: actions/checkout@v2 with: @@ -22,7 +24,9 @@ jobs: go-version: 1.21.1 - name: Install mockgen - run: go install go.uber.org/mock/mockgen@latest + run: | + go install go.uber.org/mock/mockgen@latest + go install github.com/sanposhiho/gomockhandler@latest - name: Generate mocks run: | diff --git a/app/application/middleware/auth_interface.go b/app/application/middleware/auth_interface.go index a27248f..8fff957 100644 --- a/app/application/middleware/auth_interface.go +++ b/app/application/middleware/auth_interface.go @@ -2,7 +2,7 @@ package middleware import "github.com/uptrace/bunrouter" -//go:generate mockgen -source=auth_interface.go -destination=../../mocks/auth_mocks.go -package=mocks +//go:generate gomockhandler -config=$EXAMPLE_TESTS_ROOT/gomockhandler.json -source=$GOFILE -destination=mock_$GOPACKAGE/mock_$GOFILE -package=mock_$GOPACKAGE type MiddlewareInterface interface { AuthenticateMiddleware() func(bunrouter.HandlerFunc) bunrouter.HandlerFunc CorsMiddleware() func(bunrouter.HandlerFunc) bunrouter.HandlerFunc diff --git a/app/mocks/auth_mocks.go b/app/application/middleware/mock_middleware/mock_auth_interface.go similarity index 90% rename from app/mocks/auth_mocks.go rename to app/application/middleware/mock_middleware/mock_auth_interface.go index 4e91ea0..bd09cc4 100644 --- a/app/mocks/auth_mocks.go +++ b/app/application/middleware/mock_middleware/mock_auth_interface.go @@ -1,12 +1,12 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: auth_interface.go +// Source: app/application/middleware/auth_interface.go // // Generated by this command: // -// mockgen -source=auth_interface.go -destination=../../mocks/auth_mocks.go -package=mocks +// mockgen -source=app/application/middleware/auth_interface.go -destination=app/application/middleware/mock_middleware/mock_auth_interface.go -package=mock_middleware // -// Package mocks is a generated GoMock package. -package mocks +// Package mock_middleware is a generated GoMock package. +package mock_middleware import ( reflect "reflect" diff --git a/app/mocks/user_service_mock.go b/app/application/service/mock_service/mock_user_service_interface.go similarity index 93% rename from app/mocks/user_service_mock.go rename to app/application/service/mock_service/mock_user_service_interface.go index 1d4126e..3faa373 100644 --- a/app/mocks/user_service_mock.go +++ b/app/application/service/mock_service/mock_user_service_interface.go @@ -1,12 +1,12 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: user_service_interface.go +// Source: app/application/service/user_service_interface.go // // Generated by this command: // -// mockgen -source=user_service_interface.go -destination=../../mocks/user_service_mock.go -package=mocks +// mockgen -source=app/application/service/user_service_interface.go -destination=app/application/service/mock_service/mock_user_service_interface.go -package=mock_service // -// Package mocks is a generated GoMock package. -package mocks +// Package mock_service is a generated GoMock package. +package mock_service import ( context "context" diff --git a/app/application/service/user_service_interface.go b/app/application/service/user_service_interface.go index c9379cd..a5d0f3e 100644 --- a/app/application/service/user_service_interface.go +++ b/app/application/service/user_service_interface.go @@ -5,7 +5,7 @@ import ( "example.com/domain" ) -//go:generate mockgen -source=user_service_interface.go -destination=../../mocks/user_service_mock.go -package=mocks +//go:generate gomockhandler -config=$EXAMPLE_TESTS_ROOT/gomockhandler.json -source=$GOFILE -destination=mock_$GOPACKAGE/mock_$GOFILE -package=mock_$GOPACKAGE type UserServiceInterface interface { Add(ctx context.Context, name string) (string, error) UpdateUser(ctx context.Context, user domain.User) error diff --git a/app/mocks/user_mock.go b/app/domain/repository/mock_repository/mock_user.go similarity index 94% rename from app/mocks/user_mock.go rename to app/domain/repository/mock_repository/mock_user.go index aff7d3e..a815c17 100644 --- a/app/mocks/user_mock.go +++ b/app/domain/repository/mock_repository/mock_user.go @@ -1,12 +1,12 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: user.go +// Source: app/domain/repository/user.go // // Generated by this command: // -// mockgen -source=user.go -destination=../../mocks/user_mock.go -package=mocks +// mockgen -source=app/domain/repository/user.go -destination=app/domain/repository/mock_repository/mock_user.go -package=mock_repository // -// Package mocks is a generated GoMock package. -package mocks +// Package mock_repository is a generated GoMock package. +package mock_repository import ( context "context" diff --git a/app/domain/repository/user.go b/app/domain/repository/user.go index f2001ee..201858c 100644 --- a/app/domain/repository/user.go +++ b/app/domain/repository/user.go @@ -5,7 +5,7 @@ import ( "example.com/domain" ) -//go:generate mockgen -source=user.go -destination=../../mocks/user_mock.go -package=mocks +//go:generate gomockhandler -config=$EXAMPLE_TESTS_ROOT/gomockhandler.json -source=$GOFILE -destination=mock_$GOPACKAGE/mock_$GOFILE -package=mock_$GOPACKAGE type UserRepository interface { AddUser(ctx context.Context, id, authToken, name string) error UpdateUser(ctx context.Context, user domain.User) error diff --git a/app/go.mod b/app/go.mod index 69912ef..bb7feac 100644 --- a/app/go.mod +++ b/app/go.mod @@ -4,11 +4,11 @@ go 1.21.1 require ( github.com/go-sql-driver/mysql v1.7.1 + github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.1 github.com/uptrace/bun v1.1.16 github.com/uptrace/bun/dialect/mysqldialect v1.1.16 github.com/uptrace/bunrouter v1.0.20 - go.uber.org/mock v0.3.0 ) require ( diff --git a/app/go.sum b/app/go.sum index 4a7017b..c45abc2 100644 --- a/app/go.sum +++ b/app/go.sum @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -25,12 +27,33 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9 github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= -go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +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/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/app/interface/handler/handler_interface.go b/app/interface/handler/handler_interface.go index c32e6cd..91514ab 100644 --- a/app/interface/handler/handler_interface.go +++ b/app/interface/handler/handler_interface.go @@ -2,7 +2,7 @@ package _interface import "github.com/uptrace/bunrouter" -//go:generate mockgen -source=handler_interface.go -destination=../../mocks/handler_mock.go -package=mocks +//go:generate gomockhandler -config=$EXAMPLE_TESTS_ROOT/gomockhandler.json -source=$GOFILE -destination=mock_$GOPACKAGE/mock_$GOFILE -package=mock_$GOPACKAGE type UserHandlerInterface interface { UserCreateHandle() bunrouter.HandlerFunc UserGetHandle() bunrouter.HandlerFunc diff --git a/app/mocks/handler_mock.go b/app/interface/handler/mock__interface/mock_handler_interface.go similarity index 92% rename from app/mocks/handler_mock.go rename to app/interface/handler/mock__interface/mock_handler_interface.go index 89492ff..62c4b76 100644 --- a/app/mocks/handler_mock.go +++ b/app/interface/handler/mock__interface/mock_handler_interface.go @@ -1,12 +1,12 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: handler_interface.go +// Source: app/interface/handler/handler_interface.go // // Generated by this command: // -// mockgen -source=handler_interface.go -destination=../../mocks/handler_mock.go -package=mocks +// mockgen -source=app/interface/handler/handler_interface.go -destination=app/interface/handler/mock__interface/mock_handler_interface.go -package=mock__interface // -// Package mocks is a generated GoMock package. -package mocks +// Package mock__interface is a generated GoMock package. +package mock__interface import ( reflect "reflect" diff --git a/gomockhandler.json b/gomockhandler.json new file mode 100644 index 0000000..ef3940b --- /dev/null +++ b/gomockhandler.json @@ -0,0 +1,44 @@ +{ + "mocks": { + "app/application/middleware/mock_middleware/mock_auth_interface.go": { + "checksum": "K3mIu7OMX7MwxnCjmiNj3w==", + "source_checksum": "Biu21js4aqYMt9D++o7xYg==", + "mode": "SOURCE_MODE", + "source_mode_runner": { + "source": "app/application/middleware/auth_interface.go", + "destination": "app/application/middleware/mock_middleware/mock_auth_interface.go", + "package": "mock_middleware" + } + }, + "app/application/service/mock_service/mock_user_service_interface.go": { + "checksum": "/THJPtz1/AjoFUmW8wrEBw==", + "source_checksum": "lmESALEeIbdXj7kzuANZhg==", + "mode": "SOURCE_MODE", + "source_mode_runner": { + "source": "app/application/service/user_service_interface.go", + "destination": "app/application/service/mock_service/mock_user_service_interface.go", + "package": "mock_service" + } + }, + "app/domain/repository/mock_repository/mock_user.go": { + "checksum": "gtyb9qgT5CJmzU02yszMcQ==", + "source_checksum": "TK9DZtubihm8bygk0eE3PA==", + "mode": "SOURCE_MODE", + "source_mode_runner": { + "source": "app/domain/repository/user.go", + "destination": "app/domain/repository/mock_repository/mock_user.go", + "package": "mock_repository" + } + }, + "app/interface/handler/mock__interface/mock_handler_interface.go": { + "checksum": "W707zjcJELN+P5lPMTkq3w==", + "source_checksum": "eAVARHyK054If9xuw+XKPA==", + "mode": "SOURCE_MODE", + "source_mode_runner": { + "source": "app/interface/handler/handler_interface.go", + "destination": "app/interface/handler/mock__interface/mock_handler_interface.go", + "package": "mock__interface" + } + } + } +} \ No newline at end of file