Skip to content

Commit

Permalink
Merge 905b50e into 48a5b34
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuntaoLu committed Jul 17, 2020
2 parents 48a5b34 + 905b50e commit 16f04fc
Show file tree
Hide file tree
Showing 14 changed files with 278 additions and 16 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,15 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 0.6.2 - 2020-07-17
### Added
- Added support for variadic parameters in augmented mock clients. https://github.com/uber/zanzibar/pull/731.

## 0.6.1 - 2020-07-15
### Added
- Added support for grpc clients that have multiple services defined in proto. https://github.com/uber/zanzibar/pull/730.

## 0.6.0 - 2020-07-13
### Added
- Added support for circuit breaker, logging, and metrics similar to other protocol clients for gRPC clients ([#627](https://github.com/uber/zanzibar/pull/627))
### Fixed
- Fixed some bugs around legacy JSON config file support ([#626](https://github.com/uber/zanzibar/pull/626))
### Changed
- **BREAKING** `NewDefaultModuleSystemWithMockHook` API changed to add option for which hooks to execute. ([#638](https://github.com/uber/zanzibar/pull/638))
- `resolve_thrift` tool will now check if the given file has the `.thrift` extension. ([#634](https://github.com/uber/zanzibar/pull/634))
- **BREAKING** The `genCodePackage` field type in application config file (build.yaml) is now `object` with properties `".thrift"` and `".proto"` to support separated gen code dirs for different idl types.
- **BREAKING** The `thriftRootDir` field type in application config file (build.yaml) is now `idlRootDir` since both thrift and protobuf are suppported (client idl only for now) different idl types. https://github.com/uber/zanzibar/pull/728.
- **BREAKING** The `genCodePackage` field type in application config file (build.yaml) is now `object` with properties `".thrift"` and `".proto"` to support separated gen code dirs for different idl types. https://github.com/uber/zanzibar/pull/728.


## 0.4.0 - 2019-08-21
Expand Down
13 changes: 11 additions & 2 deletions codegen/mockgen.go
Expand Up @@ -119,13 +119,20 @@ func (m MockgenBin) AugmentMockWithFixture(pkg *model.Package, f *Fixture, intf
outString = append(outString, ret)
}

methods = append(methods, &reflectMethod{
method := &reflectMethod{
Name: m.Name,
In: in,
Out: out,
InString: strings.Join(inString, " ,"),
OutString: strings.Join(outString, " ,"),
})
}

if m.Variadic != nil {
method.Variadic = "arg" + strconv.Itoa(len(m.In))
method.VariadicType = m.Variadic.Type.String(pkgPathToAlias, "")
}

methods = append(methods, method)
}

data := map[string]interface{}{
Expand All @@ -148,6 +155,8 @@ func (m MockgenBin) AugmentMockWithFixture(pkg *model.Package, f *Fixture, intf
type reflectMethod struct {
Name string
In, Out map[string]string
Variadic string
VariadicType string
InString, OutString string
}

Expand Down
28 changes: 25 additions & 3 deletions codegen/template_bundle/template_files.go

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

14 changes: 13 additions & 1 deletion codegen/templates/augmented_mock.tmpl
Expand Up @@ -89,12 +89,24 @@ func (s *{{$methodMockType}}) {{$scenarioMethod}}() Call {
{{$argName}} = gomock.Any()
}
{{- end}}
{{- if $method.Variadic}}
var {{$method.Variadic}} []interface{}
if f.{{title $method.Variadic}} != nil {
for _, v := range f.{{title $method.Variadic}} {
{{$method.Variadic}} = append({{$method.Variadic}}, v)
}
} else if f.{{title $method.Variadic}}Any > 0 {
for i := 0; i < f.{{title $method.Variadic}}Any; i++ {
{{$method.Variadic}} = append({{$method.Variadic}}, gomock.Any())
}
}
{{- end}}

{{range $retName, $retType := $method.Out}}
{{$retName}} := f.{{title $retName}}
{{- end}}

return Call{call: s.mockClient.EXPECT().{{$methodName}}({{$method.InString}}).Return({{$method.OutString}})}
return Call{call: s.mockClient.EXPECT().{{$methodName}}({{$method.InString}}{{if $method.Variadic}}, {{$method.Variadic}}...{{end}}).Return({{$method.OutString}})}
}
{{- end -}}
{{- end -}}
10 changes: 10 additions & 0 deletions codegen/templates/fixture_types.tmpl
Expand Up @@ -40,11 +40,21 @@ type {{$methodName}}Fixture struct {
{{title $argName}} {{$argType}}
{{- end}}

{{- if $method.Variadic}}
{{title $method.Variadic}} []{{$method.VariadicType}}
{{- end}}

// Arg{n}Any indicates the nth argument could be gomock.Any
{{- range $argName, $argType := $method.In}}
{{title $argName}}Any bool
{{- end}}

{{- if $method.Variadic}}
// {{title $method.Variadic}}Any indicates the variadic argument is a number of gomock.Any
{{title $method.Variadic}}Any int
{{- end}}


{{range $retName, $retType := $method.Out}}
{{title $retName}} {{$retType}}
{{- end}}
Expand Down

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

57 changes: 57 additions & 0 deletions examples/selective-gateway/build/clients/echo/mock-client/types.go

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

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

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

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

0 comments on commit 16f04fc

Please sign in to comment.