diff --git a/templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCClient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot b/templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCClient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot new file mode 100644 index 00000000..cb68acfb --- /dev/null +++ b/templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCClient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot @@ -0,0 +1,2 @@ +(*codegen.File)( +) diff --git a/templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCCLient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot b/templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCClient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot similarity index 100% rename from templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCCLient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot rename to templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCClient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot diff --git a/templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCCLient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot b/templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCClientLibrary-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot similarity index 84% rename from templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCCLient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot rename to templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCClientLibrary-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot index 4b0e0319..2719bacb 100644 --- a/templates/.snapshots/TestDontIncludeRubyToolVersionsIfNotRubyGRPCCLient-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot +++ b/templates/.snapshots/TestIncludeRubyToolVersionsIfRubyGRPCClientLibrary-testdata-tool-versions-ruby-.tool-versions.tpl-testdata-tool-versions-ruby-.tool-versions.snapshot @@ -8,4 +8,6 @@ # Used in CI - name: protoc version: 21.5 +- name: ruby + version: 3.1.3 ) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 3a961f02..c6f6c014 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -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 }} diff --git a/templates/main_test.go b/templates/main_test.go index cfa9a3a7..89837ac9 100644 --- a/templates/main_test.go +++ b/templates/main_test.go @@ -233,7 +233,7 @@ 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"}, @@ -241,7 +241,18 @@ func TestIncludeRubyToolVersionsIfRubyGRPCCLient(t *testing.T) { 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()) diff --git a/templates/testdata/tool-versions-ruby/.tool-versions.tpl b/templates/testdata/tool-versions-ruby/.tool-versions.tpl index 58481891..f594b4a9 100644 --- a/templates/testdata/tool-versions-ruby/.tool-versions.tpl +++ b/templates/testdata/tool-versions-ruby/.tool-versions.tpl @@ -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 }}