@@ -125,7 +125,7 @@ func TestRules_DisabledByInlineComments(t *testing.T) {
125125 for _ , testConfig := range testConfigurations {
126126 t .Run (test .testName + testConfig .suffix , func (t * testing.T ) {
127127 disableInline := fmt .Sprintf ("(-- api-linter: %s=disabled --)" , test .rule )
128- proto := strings .Replace (test .proto , "disable-me-here" , disableInline , - 1 )
128+ proto := strings .ReplaceAll (test .proto , "disable-me-here" , disableInline )
129129 _ , result := runLinterWithFailureStatus (t , proto , "" , testConfig .appendArgs )
130130 isDisabled := ! strings .Contains (result , test .rule )
131131 if isDisabled != testConfig .wantDisabled {
@@ -147,7 +147,7 @@ func TestRules_DisabledByConfig(t *testing.T) {
147147
148148 for _ , test := range testCases {
149149 t .Run (test .testName , func (t * testing.T ) {
150- c := strings .Replace (config , "replace-me-here" , test .rule , - 1 )
150+ c := strings .ReplaceAll (config , "replace-me-here" , test .rule )
151151 result := runLinter (t , test .proto , c )
152152 if strings .Contains (result , test .rule ) {
153153 t .Errorf ("rule %q should be disabled by the user config: %q" , test .rule , c )
@@ -178,6 +178,73 @@ func TestBuildErrors(t *testing.T) {
178178 }
179179}
180180
181+ func TestMultipleFilesFromParentDir (t * testing.T ) {
182+ // This test addresses a previously found bug:
183+ // https://github.com/googleapis/api-linter/issues/1465
184+
185+ // Skipping until Issue # 1465 is addressed
186+ t .Skip ("Skipping until Issue # 1465 is addressed" )
187+
188+ projDir , err := os .MkdirTemp ("" , "proj" )
189+ if err != nil {
190+ t .Fatal (err )
191+ }
192+ defer os .RemoveAll (projDir )
193+
194+ // Create the subdirectory for protos.
195+ protoDir := filepath .Join (projDir , "grandparent" , "parent" )
196+ if err := os .MkdirAll (protoDir , 0755 ); err != nil {
197+ t .Fatal (err )
198+ }
199+
200+ // Write the proto files.
201+ // a.proto imports b.proto.
202+ if err := writeFile (filepath .Join (protoDir , "a.proto" ), `
203+ syntax = "proto3";
204+ package grandparent.parent;
205+ import "grandparent/parent/b.proto";
206+ message A {
207+ B b_field = 1;
208+ }
209+ ` ); err != nil {
210+ t .Fatal (err )
211+ }
212+
213+ if err := writeFile (filepath .Join (protoDir , "b.proto" ), `
214+ syntax = "proto3";
215+ package grandparent.parent;
216+ message B {}
217+ ` ); err != nil {
218+ t .Fatal (err )
219+ }
220+
221+ // Change the working directory to the project root.
222+ oldWD , err := os .Getwd ()
223+ if err != nil {
224+ t .Fatal (err )
225+ }
226+ if err := os .Chdir (projDir ); err != nil {
227+ t .Fatal (err )
228+ }
229+ defer os .Chdir (oldWD )
230+
231+ args := []string {
232+ "-I" , "grandparent" ,
233+ filepath .Join ("grandparent" , "parent" , "a.proto" ),
234+ filepath .Join ("grandparent" , "parent" , "b.proto" ),
235+ }
236+
237+ err = runCLI (args )
238+
239+ if err != nil && ! errors .Is (err , ExitForLintFailure ) {
240+ if strings .Contains (err .Error (), "already defined" ) {
241+ t .Errorf ("Linter failed with unexpected 'symbol already defined' error: %v" , err )
242+ } else {
243+ t .Fatalf ("Linter failed with unexpected error: %v" , err )
244+ }
245+ }
246+ }
247+
181248func TestExitStatusForLintFailure (t * testing.T ) {
182249 type testCase struct { testName , rule , proto string }
183250 failCase := testCase {
0 commit comments