Skip to content

Commit 6374e1a

Browse files
authored
test(internal/sidekick): test to ensure path calculated correctly when both root and subdir options are present (#3996)
This test covers a scenario where the -root option already contains the subdirectory, but a -subdir option is also present. Ensure that they are not double-joined. Fix #3280
1 parent d970284 commit 6374e1a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

internal/sidekick/parser/protobuf_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,3 +2198,26 @@ func requireProtoc(t *testing.T) {
21982198
t.Skip("skipping test because protoc is not installed")
21992199
}
22002200
}
2201+
2202+
func TestProtobuf_SubdirRedundancy(t *testing.T) {
2203+
requireProtoc(t)
2204+
// This test covers a scenario where the -root option already contains the
2205+
// subdirectory, but a -subdir option is also present.
2206+
// Ensure that they are not double-joined.
2207+
options := map[string]string{
2208+
"googleapis-root": "../../testdata/googleapis",
2209+
"extra-protos-root": "testdata",
2210+
"extra-protos-subdir": "should_ignore_folder",
2211+
"include-list": "scalar.proto",
2212+
}
2213+
req, err := newCodeGeneratorRequest("testdata", options)
2214+
if err != nil {
2215+
t.Fatalf("newCodeGeneratorRequest() failed: %v", err)
2216+
}
2217+
if want, got := 1, len(req.FileToGenerate); want != got {
2218+
t.Fatalf("newCodeGeneratorRequest() returned %d files, want %d", got, want)
2219+
}
2220+
if want := "scalar.proto"; !strings.HasSuffix(req.FileToGenerate[0], want) {
2221+
t.Errorf("newCodeGeneratorRequest() returned file %q, want suffix %q", req.FileToGenerate[0], want)
2222+
}
2223+
}

0 commit comments

Comments
 (0)