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

feat: allow libraries to generate gRPC clients #470

Merged
merged 3 commits into from
Apr 2, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(*codegen.File)(
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
# Used in CI
- name: protoc
version: 21.5
- name: ruby
version: 3.1.3
)
6 changes: 3 additions & 3 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
{{- .Config.Name | replace "_" "-" | title | replace "-" "" -}}
{{- end }}

# Skips the current file if a node client shouldn't be generated
# Skips the current file if a Node.js gRPC client shouldn't be generated
# {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{{- define "skipGrpcClient" }}
{{- $grpcClient := . }}
{{- $serviceActivities := (stencil.Arg "serviceActivities") }}
{{- $grpcClients := (stencil.Arg "grpcClients") }}
{{- if not (and (has "grpc" $serviceActivities) (has $grpcClient $grpcClients)) }}
{{ file.Skip (printf "Not a gRPC service, or %s client not specified in grpcClients" $grpcClient) }}
{{- if not (and (or (not (stencil.Arg "service")) (has "grpc" $serviceActivities)) (has $grpcClient $grpcClients)) }}
malept marked this conversation as resolved.
Show resolved Hide resolved
{{ $_ := file.Skip (printf "Not a gRPC service/library, or %s client not specified in grpcClients" $grpcClient) }}
{{- end }}
{{- end }}

Expand Down
15 changes: 13 additions & 2 deletions templates/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,26 @@ func TestGRPCServerRPC(t *testing.T) {
st.Run(true)
}

func TestIncludeRubyToolVersionsIfRubyGRPCCLient(t *testing.T) {
func TestIncludeRubyToolVersionsIfRubyGRPCClient(t *testing.T) {
st := stenciltest.New(t, "testdata/tool-versions-ruby/.tool-versions.tpl", libraryTmpls...)
st.Args(map[string]interface{}{
"grpcClients": []interface{}{"ruby"},
})
st.Run(stenciltest.RegenerateSnapshots())
}

func TestDontIncludeRubyToolVersionsIfNotRubyGRPCCLient(t *testing.T) {
func TestIncludeRubyToolVersionsIfRubyGRPCClientLibrary(t *testing.T) {
// Need to use testdata because stenciltest cannot test file.Skip
st := stenciltest.New(t, "testdata/tool-versions-ruby/.tool-versions.tpl", libraryTmpls...)
st.Args(map[string]interface{}{
"grpcClients": []interface{}{"ruby"},
"service": false,
"serviceActivities": []interface{}{},
})
st.Run(stenciltest.RegenerateSnapshots())
}

func TestDontIncludeRubyToolVersionsIfNotRubyGRPCClient(t *testing.T) {
st := stenciltest.New(t, "testdata/tool-versions-ruby/.tool-versions.tpl", libraryTmpls...)
st.Args(map[string]interface{}{})
st.Run(stenciltest.RegenerateSnapshots())
Expand Down
4 changes: 4 additions & 0 deletions templates/testdata/tool-versions-ruby/.tool-versions.tpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
{{- $_ := file.Skip "Test file" }}
{{- $serviceActivities := (stencil.Arg "serviceActivities") }}
{{- $grpcClients := (stencil.Arg "grpcClients") }}
{{- if and (or (not (stencil.Arg "service")) (has "grpc" $serviceActivities)) (has "ruby" $grpcClients) }}
{{ stencil.ApplyTemplate "toolVersions" }}
{{- end }}