github.com/Minish144/prototool-arm64@v1.3.0/internal/file/proto_set_provider_test.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package file 22 23 import ( 24 "os" 25 "path/filepath" 26 "testing" 27 28 "github.com/stretchr/testify/assert" 29 "github.com/stretchr/testify/require" 30 "github.com/uber/prototool/internal/settings" 31 "go.uber.org/zap" 32 ) 33 34 func TestProtoSetProviderGetMultipleForFilesAll(t *testing.T) { 35 cwd, err := os.Getwd() 36 require.NoError(t, err) 37 protoSetProvider := newTestProtoSetProvider(t) 38 protoSets, err := protoSetProvider.GetMultipleForFiles( 39 cwd, 40 "testdata/valid/base/a/file.proto", 41 "testdata/valid/base/b/file.proto", 42 "testdata/valid/base/c/file.proto", 43 "testdata/valid/base/a/d/file.proto", 44 "testdata/valid/base/a/d/file2.proto", 45 "testdata/valid/base/a/d/file3.proto", 46 "testdata/valid/base/a/e/file.proto", 47 "testdata/valid/base/a/f/file.proto", 48 "testdata/valid/base/b/g/h/file.proto", 49 ) 50 require.NoError(t, err) 51 require.Equal( 52 t, 53 []*ProtoSet{ 54 &ProtoSet{ 55 WorkDirPath: cwd, 56 DirPath: cwd, 57 DirPathToFiles: map[string][]*ProtoFile{ 58 cwd + "/testdata/valid/base/a": []*ProtoFile{ 59 { 60 Path: cwd + "/testdata/valid/base/a/file.proto", 61 DisplayPath: "testdata/valid/base/a/file.proto", 62 }, 63 }, 64 cwd + "/testdata/valid/base/c": []*ProtoFile{ 65 { 66 Path: cwd + "/testdata/valid/base/c/file.proto", 67 DisplayPath: "testdata/valid/base/c/file.proto", 68 }, 69 }, 70 cwd + "/testdata/valid/base/a/e": []*ProtoFile{ 71 { 72 Path: cwd + "/testdata/valid/base/a/e/file.proto", 73 DisplayPath: "testdata/valid/base/a/e/file.proto", 74 }, 75 }, 76 cwd + "/testdata/valid/base/a/f": []*ProtoFile{ 77 { 78 Path: cwd + "/testdata/valid/base/a/f/file.proto", 79 DisplayPath: "testdata/valid/base/a/f/file.proto", 80 }, 81 }, 82 }, 83 Config: settings.Config{ 84 DirPath: cwd + "/testdata/valid/base", 85 ExcludePrefixes: []string{ 86 cwd + "/testdata/valid/base/c/i", 87 cwd + "/testdata/valid/base/d", 88 }, 89 Compile: settings.CompileConfig{ 90 ProtobufVersion: "3.4.0", 91 IncludePaths: []string{}, 92 IncludeWellKnownTypes: true, 93 }, 94 Lint: settings.LintConfig{ 95 IncludeIDs: []string{}, 96 ExcludeIDs: []string{}, 97 IgnoreIDToFilePaths: map[string][]string{}, 98 }, 99 Gen: settings.GenConfig{ 100 GoPluginOptions: settings.GenGoPluginOptions{}, 101 Plugins: []settings.GenPlugin{}, 102 }, 103 }, 104 }, 105 &ProtoSet{ 106 WorkDirPath: cwd, 107 DirPath: cwd, 108 DirPathToFiles: map[string][]*ProtoFile{ 109 cwd + "/testdata/valid/base/a/d": []*ProtoFile{ 110 { 111 Path: cwd + "/testdata/valid/base/a/d/file.proto", 112 DisplayPath: "testdata/valid/base/a/d/file.proto", 113 }, 114 { 115 Path: cwd + "/testdata/valid/base/a/d/file2.proto", 116 DisplayPath: "testdata/valid/base/a/d/file2.proto", 117 }, 118 { 119 Path: cwd + "/testdata/valid/base/a/d/file3.proto", 120 DisplayPath: "testdata/valid/base/a/d/file3.proto", 121 }, 122 }, 123 }, 124 Config: settings.Config{ 125 DirPath: cwd + "/testdata/valid/base/a/d", 126 ExcludePrefixes: []string{ 127 cwd + "/testdata/valid/base/a/d/file3.proto", 128 }, 129 Compile: settings.CompileConfig{ 130 ProtobufVersion: "3.2.0", 131 IncludePaths: []string{}, 132 IncludeWellKnownTypes: true, 133 }, 134 Lint: settings.LintConfig{ 135 IncludeIDs: []string{}, 136 ExcludeIDs: []string{}, 137 IgnoreIDToFilePaths: map[string][]string{}, 138 }, 139 Gen: settings.GenConfig{ 140 GoPluginOptions: settings.GenGoPluginOptions{}, 141 Plugins: []settings.GenPlugin{}, 142 }, 143 }, 144 }, 145 &ProtoSet{ 146 WorkDirPath: cwd, 147 DirPath: cwd, 148 DirPathToFiles: map[string][]*ProtoFile{ 149 cwd + "/testdata/valid/base/b": []*ProtoFile{ 150 { 151 Path: cwd + "/testdata/valid/base/b/file.proto", 152 DisplayPath: "testdata/valid/base/b/file.proto", 153 }, 154 }, 155 cwd + "/testdata/valid/base/b/g/h": []*ProtoFile{ 156 { 157 Path: cwd + "/testdata/valid/base/b/g/h/file.proto", 158 DisplayPath: "testdata/valid/base/b/g/h/file.proto", 159 }, 160 }, 161 }, 162 Config: settings.Config{ 163 DirPath: cwd + "/testdata/valid/base/b", 164 ExcludePrefixes: []string{ 165 cwd + "/testdata/valid/base/b/g/h", 166 }, 167 Compile: settings.CompileConfig{ 168 ProtobufVersion: "3.3.0", 169 IncludePaths: []string{}, 170 IncludeWellKnownTypes: true, 171 }, 172 Lint: settings.LintConfig{ 173 IncludeIDs: []string{}, 174 ExcludeIDs: []string{}, 175 IgnoreIDToFilePaths: map[string][]string{}, 176 }, 177 Gen: settings.GenConfig{ 178 GoPluginOptions: settings.GenGoPluginOptions{}, 179 Plugins: []settings.GenPlugin{}, 180 }, 181 }, 182 }, 183 }, 184 protoSets, 185 ) 186 } 187 188 func TestProtoSetProviderGetMultipleForFilesSomeMissing(t *testing.T) { 189 cwd, err := os.Getwd() 190 require.NoError(t, err) 191 protoSetProvider := newTestProtoSetProvider(t) 192 protoSets, err := protoSetProvider.GetMultipleForFiles( 193 cwd, 194 "testdata/valid/base/a/file.proto", 195 "testdata/valid/base/c/file.proto", 196 "testdata/valid/base/a/d/file.proto", 197 "testdata/valid/base/a/d/file3.proto", 198 "testdata/valid/base/a/e/file.proto", 199 "testdata/valid/base/a/f/file.proto", 200 ) 201 require.NoError(t, err) 202 require.Equal( 203 t, 204 []*ProtoSet{ 205 &ProtoSet{ 206 WorkDirPath: cwd, 207 DirPath: cwd, 208 DirPathToFiles: map[string][]*ProtoFile{ 209 cwd + "/testdata/valid/base/a": []*ProtoFile{ 210 { 211 Path: cwd + "/testdata/valid/base/a/file.proto", 212 DisplayPath: "testdata/valid/base/a/file.proto", 213 }, 214 }, 215 cwd + "/testdata/valid/base/c": []*ProtoFile{ 216 { 217 Path: cwd + "/testdata/valid/base/c/file.proto", 218 DisplayPath: "testdata/valid/base/c/file.proto", 219 }, 220 }, 221 cwd + "/testdata/valid/base/a/e": []*ProtoFile{ 222 { 223 Path: cwd + "/testdata/valid/base/a/e/file.proto", 224 DisplayPath: "testdata/valid/base/a/e/file.proto", 225 }, 226 }, 227 cwd + "/testdata/valid/base/a/f": []*ProtoFile{ 228 { 229 Path: cwd + "/testdata/valid/base/a/f/file.proto", 230 DisplayPath: "testdata/valid/base/a/f/file.proto", 231 }, 232 }, 233 }, 234 Config: settings.Config{ 235 DirPath: cwd + "/testdata/valid/base", 236 ExcludePrefixes: []string{ 237 cwd + "/testdata/valid/base/c/i", 238 cwd + "/testdata/valid/base/d", 239 }, 240 Compile: settings.CompileConfig{ 241 ProtobufVersion: "3.4.0", 242 IncludePaths: []string{}, 243 IncludeWellKnownTypes: true, 244 }, 245 Lint: settings.LintConfig{ 246 IncludeIDs: []string{}, 247 ExcludeIDs: []string{}, 248 IgnoreIDToFilePaths: map[string][]string{}, 249 }, 250 Gen: settings.GenConfig{ 251 GoPluginOptions: settings.GenGoPluginOptions{}, 252 Plugins: []settings.GenPlugin{}, 253 }, 254 }, 255 }, 256 &ProtoSet{ 257 WorkDirPath: cwd, 258 DirPath: cwd, 259 DirPathToFiles: map[string][]*ProtoFile{ 260 cwd + "/testdata/valid/base/a/d": []*ProtoFile{ 261 { 262 Path: cwd + "/testdata/valid/base/a/d/file.proto", 263 DisplayPath: "testdata/valid/base/a/d/file.proto", 264 }, 265 { 266 Path: cwd + "/testdata/valid/base/a/d/file3.proto", 267 DisplayPath: "testdata/valid/base/a/d/file3.proto", 268 }, 269 }, 270 }, 271 Config: settings.Config{ 272 DirPath: cwd + "/testdata/valid/base/a/d", 273 ExcludePrefixes: []string{ 274 cwd + "/testdata/valid/base/a/d/file3.proto", 275 }, 276 Compile: settings.CompileConfig{ 277 ProtobufVersion: "3.2.0", 278 IncludePaths: []string{}, 279 IncludeWellKnownTypes: true, 280 }, 281 Lint: settings.LintConfig{ 282 IncludeIDs: []string{}, 283 ExcludeIDs: []string{}, 284 IgnoreIDToFilePaths: map[string][]string{}, 285 }, 286 Gen: settings.GenConfig{ 287 GoPluginOptions: settings.GenGoPluginOptions{}, 288 Plugins: []settings.GenPlugin{}, 289 }, 290 }, 291 }, 292 }, 293 protoSets, 294 ) 295 } 296 297 // We need to use valid as a representation of "cwd" so we verify 298 // that we do the recursive search properly. We used to use actual cwd, 299 // however since we added testdata/invalid, this will not work anymore. 300 // This is why we have the subdirectory "base" inside valid. 301 func TestProtoSetProviderGetMultipleForDirCwdAsValidRel(t *testing.T) { 302 cwd, err := os.Getwd() 303 require.NoError(t, err) 304 validDirPath := filepath.Join(cwd, "testdata", "valid") 305 protoSetProvider := newTestProtoSetProvider(t) 306 protoSets, err := protoSetProvider.GetMultipleForDir(cwd, filepath.Join(".", "testdata", "valid")) 307 require.NoError(t, err) 308 require.Equal( 309 t, 310 []*ProtoSet{ 311 &ProtoSet{ 312 WorkDirPath: cwd, 313 DirPath: validDirPath, 314 DirPathToFiles: map[string][]*ProtoFile{ 315 cwd + "/testdata/valid/base/a": []*ProtoFile{ 316 { 317 Path: cwd + "/testdata/valid/base/a/file.proto", 318 DisplayPath: "testdata/valid/base/a/file.proto", 319 }, 320 }, 321 cwd + "/testdata/valid/base/c": []*ProtoFile{ 322 { 323 Path: cwd + "/testdata/valid/base/c/file.proto", 324 DisplayPath: "testdata/valid/base/c/file.proto", 325 }, 326 }, 327 cwd + "/testdata/valid/base/a/e": []*ProtoFile{ 328 { 329 Path: cwd + "/testdata/valid/base/a/e/file.proto", 330 DisplayPath: "testdata/valid/base/a/e/file.proto", 331 }, 332 }, 333 cwd + "/testdata/valid/base/a/f": []*ProtoFile{ 334 { 335 Path: cwd + "/testdata/valid/base/a/f/file.proto", 336 DisplayPath: "testdata/valid/base/a/f/file.proto", 337 }, 338 }, 339 }, 340 Config: settings.Config{ 341 DirPath: cwd + "/testdata/valid/base", 342 ExcludePrefixes: []string{ 343 cwd + "/testdata/valid/base/c/i", 344 cwd + "/testdata/valid/base/d", 345 }, 346 Compile: settings.CompileConfig{ 347 ProtobufVersion: "3.4.0", 348 IncludePaths: []string{}, 349 IncludeWellKnownTypes: true, 350 }, 351 Lint: settings.LintConfig{ 352 IncludeIDs: []string{}, 353 ExcludeIDs: []string{}, 354 IgnoreIDToFilePaths: map[string][]string{}, 355 }, 356 Gen: settings.GenConfig{ 357 GoPluginOptions: settings.GenGoPluginOptions{}, 358 Plugins: []settings.GenPlugin{}, 359 }, 360 }, 361 }, 362 &ProtoSet{ 363 WorkDirPath: cwd, 364 DirPath: validDirPath, 365 DirPathToFiles: map[string][]*ProtoFile{ 366 cwd + "/testdata/valid/base/a/d": []*ProtoFile{ 367 { 368 Path: cwd + "/testdata/valid/base/a/d/file.proto", 369 DisplayPath: "testdata/valid/base/a/d/file.proto", 370 }, 371 { 372 Path: cwd + "/testdata/valid/base/a/d/file2.proto", 373 DisplayPath: "testdata/valid/base/a/d/file2.proto", 374 }, 375 }, 376 }, 377 Config: settings.Config{ 378 DirPath: cwd + "/testdata/valid/base/a/d", 379 ExcludePrefixes: []string{ 380 cwd + "/testdata/valid/base/a/d/file3.proto", 381 }, 382 Compile: settings.CompileConfig{ 383 ProtobufVersion: "3.2.0", 384 IncludePaths: []string{}, 385 IncludeWellKnownTypes: true, 386 }, 387 Lint: settings.LintConfig{ 388 IncludeIDs: []string{}, 389 ExcludeIDs: []string{}, 390 IgnoreIDToFilePaths: map[string][]string{}, 391 }, 392 Gen: settings.GenConfig{ 393 GoPluginOptions: settings.GenGoPluginOptions{}, 394 Plugins: []settings.GenPlugin{}, 395 }, 396 }, 397 }, 398 &ProtoSet{ 399 WorkDirPath: cwd, 400 DirPath: validDirPath, 401 DirPathToFiles: map[string][]*ProtoFile{ 402 cwd + "/testdata/valid/base/b": []*ProtoFile{ 403 { 404 Path: cwd + "/testdata/valid/base/b/file.proto", 405 DisplayPath: "testdata/valid/base/b/file.proto", 406 }, 407 }, 408 }, 409 Config: settings.Config{ 410 DirPath: cwd + "/testdata/valid/base/b", 411 ExcludePrefixes: []string{ 412 cwd + "/testdata/valid/base/b/g/h", 413 }, 414 Compile: settings.CompileConfig{ 415 ProtobufVersion: "3.3.0", 416 IncludePaths: []string{}, 417 IncludeWellKnownTypes: true, 418 }, 419 Lint: settings.LintConfig{ 420 IncludeIDs: []string{}, 421 ExcludeIDs: []string{}, 422 IgnoreIDToFilePaths: map[string][]string{}, 423 }, 424 Gen: settings.GenConfig{ 425 GoPluginOptions: settings.GenGoPluginOptions{}, 426 Plugins: []settings.GenPlugin{}, 427 }, 428 }, 429 }, 430 }, 431 protoSets, 432 ) 433 } 434 435 // We need to use valid as a representation of "cwd" so we verify 436 // that we do the recursive search properly. We used to use actual cwd, 437 // however since we added testdata/invalid, this will not work anymore. 438 // This is why we have the subdirectory "base" inside valid. 439 func TestProtoSetProviderGetMultipleForDirCwdAbs(t *testing.T) { 440 cwd, err := os.Getwd() 441 require.NoError(t, err) 442 validDirPath := filepath.Join(cwd, "testdata", "valid") 443 protoSetProvider := newTestProtoSetProvider(t) 444 protoSets, err := protoSetProvider.GetMultipleForDir(cwd, validDirPath) 445 require.NoError(t, err) 446 require.Equal( 447 t, 448 []*ProtoSet{ 449 &ProtoSet{ 450 WorkDirPath: cwd, 451 DirPath: validDirPath, 452 DirPathToFiles: map[string][]*ProtoFile{ 453 cwd + "/testdata/valid/base/a": []*ProtoFile{ 454 { 455 Path: cwd + "/testdata/valid/base/a/file.proto", 456 DisplayPath: "testdata/valid/base/a/file.proto", 457 }, 458 }, 459 cwd + "/testdata/valid/base/c": []*ProtoFile{ 460 { 461 Path: cwd + "/testdata/valid/base/c/file.proto", 462 DisplayPath: "testdata/valid/base/c/file.proto", 463 }, 464 }, 465 cwd + "/testdata/valid/base/a/e": []*ProtoFile{ 466 { 467 Path: cwd + "/testdata/valid/base/a/e/file.proto", 468 DisplayPath: "testdata/valid/base/a/e/file.proto", 469 }, 470 }, 471 cwd + "/testdata/valid/base/a/f": []*ProtoFile{ 472 { 473 Path: cwd + "/testdata/valid/base/a/f/file.proto", 474 DisplayPath: "testdata/valid/base/a/f/file.proto", 475 }, 476 }, 477 }, 478 Config: settings.Config{ 479 DirPath: cwd + "/testdata/valid/base", 480 ExcludePrefixes: []string{ 481 cwd + "/testdata/valid/base/c/i", 482 cwd + "/testdata/valid/base/d", 483 }, 484 Compile: settings.CompileConfig{ 485 ProtobufVersion: "3.4.0", 486 IncludePaths: []string{}, 487 IncludeWellKnownTypes: true, 488 }, 489 Lint: settings.LintConfig{ 490 IncludeIDs: []string{}, 491 ExcludeIDs: []string{}, 492 IgnoreIDToFilePaths: map[string][]string{}, 493 }, 494 Gen: settings.GenConfig{ 495 GoPluginOptions: settings.GenGoPluginOptions{}, 496 Plugins: []settings.GenPlugin{}, 497 }, 498 }, 499 }, 500 &ProtoSet{ 501 WorkDirPath: cwd, 502 DirPath: validDirPath, 503 DirPathToFiles: map[string][]*ProtoFile{ 504 cwd + "/testdata/valid/base/a/d": []*ProtoFile{ 505 { 506 Path: cwd + "/testdata/valid/base/a/d/file.proto", 507 DisplayPath: "testdata/valid/base/a/d/file.proto", 508 }, 509 { 510 Path: cwd + "/testdata/valid/base/a/d/file2.proto", 511 DisplayPath: "testdata/valid/base/a/d/file2.proto", 512 }, 513 }, 514 }, 515 Config: settings.Config{ 516 DirPath: cwd + "/testdata/valid/base/a/d", 517 ExcludePrefixes: []string{ 518 cwd + "/testdata/valid/base/a/d/file3.proto", 519 }, 520 Compile: settings.CompileConfig{ 521 ProtobufVersion: "3.2.0", 522 IncludePaths: []string{}, 523 IncludeWellKnownTypes: true, 524 }, 525 Lint: settings.LintConfig{ 526 IncludeIDs: []string{}, 527 ExcludeIDs: []string{}, 528 IgnoreIDToFilePaths: map[string][]string{}, 529 }, 530 Gen: settings.GenConfig{ 531 GoPluginOptions: settings.GenGoPluginOptions{}, 532 Plugins: []settings.GenPlugin{}, 533 }, 534 }, 535 }, 536 &ProtoSet{ 537 WorkDirPath: cwd, 538 DirPath: validDirPath, 539 DirPathToFiles: map[string][]*ProtoFile{ 540 cwd + "/testdata/valid/base/b": []*ProtoFile{ 541 { 542 Path: cwd + "/testdata/valid/base/b/file.proto", 543 DisplayPath: "testdata/valid/base/b/file.proto", 544 }, 545 }, 546 }, 547 Config: settings.Config{ 548 DirPath: cwd + "/testdata/valid/base/b", 549 ExcludePrefixes: []string{ 550 cwd + "/testdata/valid/base/b/g/h", 551 }, 552 Compile: settings.CompileConfig{ 553 ProtobufVersion: "3.3.0", 554 IncludePaths: []string{}, 555 IncludeWellKnownTypes: true, 556 }, 557 Lint: settings.LintConfig{ 558 IncludeIDs: []string{}, 559 ExcludeIDs: []string{}, 560 IgnoreIDToFilePaths: map[string][]string{}, 561 }, 562 Gen: settings.GenConfig{ 563 GoPluginOptions: settings.GenGoPluginOptions{}, 564 Plugins: []settings.GenPlugin{}, 565 }, 566 }, 567 }, 568 }, 569 protoSets, 570 ) 571 } 572 573 func TestProtoSetProviderGetMultipleForDirCwdSubRel(t *testing.T) { 574 cwd, err := os.Getwd() 575 require.NoError(t, err) 576 protoSetProvider := newTestProtoSetProvider(t) 577 protoSets, err := protoSetProvider.GetMultipleForDir(cwd, "testdata/valid/base/d/g") 578 require.NoError(t, err) 579 require.Equal( 580 t, 581 []*ProtoSet{ 582 &ProtoSet{ 583 WorkDirPath: cwd, 584 DirPath: cwd + "/testdata/valid/base/d/g", 585 DirPathToFiles: map[string][]*ProtoFile{ 586 cwd + "/testdata/valid/base/d": []*ProtoFile{ 587 { 588 Path: cwd + "/testdata/valid/base/d/file.proto", 589 DisplayPath: "testdata/valid/base/d/file.proto", 590 }, 591 }, 592 cwd + "/testdata/valid/base/d/g/h": []*ProtoFile{ 593 { 594 Path: cwd + "/testdata/valid/base/d/g/h/file.proto", 595 DisplayPath: "testdata/valid/base/d/g/h/file.proto", 596 }, 597 }, 598 }, 599 Config: settings.Config{ 600 DirPath: cwd + "/testdata/valid/base/d", 601 ExcludePrefixes: []string{}, 602 Compile: settings.CompileConfig{ 603 ProtobufVersion: "3.3.0", 604 IncludePaths: []string{}, 605 IncludeWellKnownTypes: true, 606 }, 607 Lint: settings.LintConfig{ 608 IncludeIDs: []string{}, 609 ExcludeIDs: []string{}, 610 IgnoreIDToFilePaths: map[string][]string{}, 611 }, 612 Gen: settings.GenConfig{ 613 GoPluginOptions: settings.GenGoPluginOptions{}, 614 Plugins: []settings.GenPlugin{}, 615 }, 616 }, 617 }, 618 }, 619 protoSets, 620 ) 621 } 622 623 func TestProtoSetProviderGetMultipleForDirTwoConfigFiles(t *testing.T) { 624 cwd, err := os.Getwd() 625 require.NoError(t, err) 626 protoSetProvider := newTestProtoSetProvider(t) 627 _, err = protoSetProvider.GetMultipleForDir(cwd, "testdata/invalid") 628 require.Error(t, err) 629 require.Contains(t, err.Error(), "multiple configuration files") 630 } 631 632 func TestIsExcluded(t *testing.T) { 633 cwd, err := os.Getwd() 634 require.NoError(t, err) 635 636 tests := []struct { 637 desc string 638 filePath string 639 stopPath string 640 excludes map[string]struct{} 641 excluded bool 642 }{ 643 { 644 desc: "Nothing excluded", 645 filePath: cwd, 646 excluded: false, 647 }, 648 { 649 desc: "String prefix of excluded dir is not excluded", 650 filePath: filepath.Join(cwd, "foo"), 651 stopPath: cwd, 652 excludes: map[string]struct{}{filepath.Join(cwd, "fooo"): struct{}{}}, 653 excluded: false, 654 }, 655 { 656 desc: "Not excluded, terminates without stopPath", 657 filePath: filepath.Join(cwd, "foo"), 658 excludes: map[string]struct{}{filepath.Join(cwd, "bar"): struct{}{}}, 659 excluded: false, 660 }, 661 { 662 desc: "Directory is exluded", 663 filePath: filepath.Join(cwd, "foo/bar"), 664 stopPath: cwd, 665 excludes: map[string]struct{}{filepath.Join(cwd, "foo"): struct{}{}}, 666 excluded: true, 667 }, 668 { 669 desc: "File is exluded", 670 filePath: filepath.Join(cwd, "foo.proto"), 671 stopPath: cwd, 672 excludes: map[string]struct{}{filepath.Join(cwd, "foo.proto"): struct{}{}}, 673 excluded: true, 674 }, 675 } 676 for _, tt := range tests { 677 t.Run(tt.desc, func(t *testing.T) { 678 assert.Equal(t, tt.excluded, isExcluded(tt.filePath, tt.stopPath, tt.excludes)) 679 }) 680 } 681 } 682 683 func newTestProtoSetProvider(t *testing.T) ProtoSetProvider { 684 logger, err := zap.NewDevelopment() 685 require.NoError(t, err) 686 return NewProtoSetProvider(ProtoSetProviderWithLogger(logger)) 687 }