diff --git a/protoc-gen-rails/main_test.go b/protoc-gen-rails/main_test.go index 609833f..e3ad94a 100644 --- a/protoc-gen-rails/main_test.go +++ b/protoc-gen-rails/main_test.go @@ -33,7 +33,9 @@ func fileNames(directory string, appendDirectory bool, extension string) ([]stri return nil } files = append(files, info) - fullPaths = append(fullPaths, path) + if info.Name() != ".keep" { + fullPaths = append(fullPaths, path) + } if err != nil { fmt.Println("ERROR:", err) } @@ -89,6 +91,25 @@ func Test_Base(t *testing.T) { runTest(t, "base", map[string]string{}) } +func Test_NoServices(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := os.MkdirTemp(workdir, "proto-test.") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + args := []string{ + "-I.", + "--rails_out=" + tmpdir, + } + args = append(args, fmt.Sprintf("testdata/test.proto")) + protoc(t, args) + + testDir := workdir + "/testdata/no_service" + assertEqualFiles(t, testDir, tmpdir) +} + func assertEqualFiles(t *testing.T, original, generated string) { names, err := fileNames(original, false, "") if err != nil { diff --git a/protoc-gen-rails/testdata/base/config/routes/grpc.rb b/protoc-gen-rails/testdata/base/config/routes/grpc.rb index ec1d152..d50272e 100644 --- a/protoc-gen-rails/testdata/base/config/routes/grpc.rb +++ b/protoc-gen-rails/testdata/base/config/routes/grpc.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true ####### THIS FILE IS AUTOMATICALLY GENERATED BY protoc-gen-rails. DO NOT MODIFY. ####### -get "/test/:blah/:repeated_string" => "my_service#test" -post "/test2" => "my_service#test_2" -post "/test3/:sub_id" => "my_service#test_3" +get '/test/:blah/:repeated_string' => 'my_service#test' +post '/test2' => 'my_service#test_2' +post '/test3/:sub_id' => 'my_service#test_3' diff --git a/protoc-gen-rails/testdata/no_service/.keep b/protoc-gen-rails/testdata/no_service/.keep new file mode 100644 index 0000000..e69de29 diff --git a/protoc-gen-rails/testdata/test.proto b/protoc-gen-rails/testdata/test.proto new file mode 100644 index 0000000..331c23e --- /dev/null +++ b/protoc-gen-rails/testdata/test.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +package test; + +message Test { + string test = 1; +}