Skip to content

Commit

Permalink
Add test for no services
Browse files Browse the repository at this point in the history
  • Loading branch information
dorner committed Apr 5, 2024
1 parent c6b3883 commit 35f8f98
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
23 changes: 22 additions & 1 deletion protoc-gen-rails/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions protoc-gen-rails/testdata/base/config/routes/grpc.rb
Original file line number Diff line number Diff line change
@@ -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'
Empty file.
6 changes: 6 additions & 0 deletions protoc-gen-rails/testdata/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";
package test;

message Test {
string test = 1;
}

0 comments on commit 35f8f98

Please sign in to comment.