Skip to content

Commit

Permalink
feat: allow libraries to generate gRPC clients (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored and willcj33 committed Apr 2, 2024
1 parent 50ade01 commit d5d5425
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
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)) }}
{{ $_ := 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 }}

0 comments on commit d5d5425

Please sign in to comment.