Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thriftrw-plugin-yarpc: Support go.uber.org/mock #2236

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
- grpc: returned outbound response body is no longer writable.
- Fixed panic when error details list contains message that cannot be unmarshalled.
- thriftrw-plugin-yarpc: Add option for configuring the mock library.

## [1.70.4] - 2023-08-31
- logging: fix logged error in observability middleware when fields of transport.Request is in the tagsBlocklist
Expand Down
2 changes: 1 addition & 1 deletion encoding/thrift/thriftrw-plugin-yarpc/gomock.go

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

16 changes: 15 additions & 1 deletion encoding/thrift/thriftrw-plugin-yarpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ package main

import (
"flag"
"fmt"
"strings"

"go.uber.org/thriftrw/plugin"
"go.uber.org/thriftrw/plugin/api"
)

// mock libraries
const (
_golangMock = "github.com/golang/mock/gomock"
_uberMock = "go.uber.org/mock/gomock"
)

// Command line flags
var (
_context = flag.String("context-import-path",
Expand All @@ -82,7 +89,9 @@ var (
"go.uber.org/yarpc/encoding/thrift.OnewayHandler",
"Function used to wrap generic Thrift oneway function handlers into YARPC handlers")
_noGomock = flag.Bool("no-gomock", false,
"Don't generate gomock mocks for service clients")
"Don't generate mocks for service clients")
_mockLibrary = flag.String("mock-library", _golangMock,
fmt.Sprintf("Mock library service clients are generated with. Supported options: %q %q", _golangMock, _uberMock))
_noFx = flag.Bool("no-fx", false, "Don't generate Fx module")
_sanitizeTChannel = flag.Bool("sanitize-tchannel", false, "Enable tchannel context sanitization")
)
Expand All @@ -106,6 +115,10 @@ func (g g) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceRespon
serviceGenerators = append(serviceGenerators, gomockGenerator)
}

if !(*_mockLibrary == _golangMock || *_mockLibrary == _uberMock) {
return nil, fmt.Errorf("%q specified as mock-library. expected %q or %q", *_mockLibrary, _golangMock, _uberMock)
}

unaryWrapperImport, unaryWrapperFunc := splitFunctionPath(*_unaryHandlerWrapper)
onewayWrapperImport, onewayWrapperFunc := splitFunctionPath(*_onewayHandlerWrapper)

Expand All @@ -115,6 +128,7 @@ func (g g) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceRespon
data := serviceTemplateData{
Svc: buildSvc(serviceID, req),
ContextImportPath: *_context,
MockLibrary: *_mockLibrary,
UnaryWrapperImport: unaryWrapperImport,
UnaryWrapperFunc: unaryWrapperFunc,
OnewayWrapperImport: onewayWrapperImport,
Expand Down
1 change: 1 addition & 0 deletions encoding/thrift/thriftrw-plugin-yarpc/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type serviceTemplateData struct {
OnewayWrapperImport string
OnewayWrapperFunc string
SanitizeTChannel bool
MockLibrary string
}

// moduleTemplateData contains the data for code gen templates. This should be
Expand Down