|
480 | 480 | end |
481 | 481 | end |
482 | 482 | end |
| 483 | + |
| 484 | + describe "::from_job_config validation" do |
| 485 | + let(:dependency_groups_config) do |
| 486 | + [ |
| 487 | + { |
| 488 | + "name" => "test-group", |
| 489 | + "rules" => { |
| 490 | + "dependency-type" => "production" |
| 491 | + } |
| 492 | + } |
| 493 | + ] |
| 494 | + end |
| 495 | + |
| 496 | + context "when dependency-type is used with a supported package manager" do |
| 497 | + %w[bundler composer hex maven npm_and_yarn pip uv].each do |package_manager| |
| 498 | + context "with #{package_manager}" do |
| 499 | + let(:job) do |
| 500 | + instance_double( |
| 501 | + Dependabot::Job, |
| 502 | + dependency_groups: dependency_groups_config, |
| 503 | + source: source, |
| 504 | + dependencies: nil, |
| 505 | + security_updates_only?: false, |
| 506 | + package_manager: package_manager |
| 507 | + ) |
| 508 | + end |
| 509 | + |
| 510 | + it "does not raise an error" do |
| 511 | + expect { dependency_group_engine }.not_to raise_error |
| 512 | + end |
| 513 | + end |
| 514 | + end |
| 515 | + end |
| 516 | + |
| 517 | + context "when dependency-type is used with an unsupported package manager" do |
| 518 | + %w[gradle go_modules cargo docker terraform].each do |package_manager| |
| 519 | + context "with #{package_manager}" do |
| 520 | + let(:job) do |
| 521 | + instance_double( |
| 522 | + Dependabot::Job, |
| 523 | + dependency_groups: dependency_groups_config, |
| 524 | + source: source, |
| 525 | + dependencies: nil, |
| 526 | + security_updates_only?: false, |
| 527 | + package_manager: package_manager |
| 528 | + ) |
| 529 | + end |
| 530 | + |
| 531 | + it "raises a ConfigurationError" do |
| 532 | + expect { dependency_group_engine }.to raise_error( |
| 533 | + Dependabot::DependencyGroupEngine::ConfigurationError, |
| 534 | + /The 'dependency-type' option is not supported for the '#{package_manager}' package manager/ |
| 535 | + ) |
| 536 | + end |
| 537 | + |
| 538 | + it "includes the group name in the error message" do |
| 539 | + expect { dependency_group_engine }.to raise_error( |
| 540 | + Dependabot::DependencyGroupEngine::ConfigurationError, |
| 541 | + /Affected groups: test-group/ |
| 542 | + ) |
| 543 | + end |
| 544 | + |
| 545 | + it "lists supported package managers in the error message" do |
| 546 | + expect { dependency_group_engine }.to raise_error( |
| 547 | + Dependabot::DependencyGroupEngine::ConfigurationError, |
| 548 | + /bundler, composer, hex, maven, npm_and_yarn, pip, uv/ |
| 549 | + ) |
| 550 | + end |
| 551 | + end |
| 552 | + end |
| 553 | + end |
| 554 | + |
| 555 | + context "when multiple groups use dependency-type with an unsupported package manager" do |
| 556 | + let(:dependency_groups_config) do |
| 557 | + [ |
| 558 | + { |
| 559 | + "name" => "group-one", |
| 560 | + "rules" => { |
| 561 | + "dependency-type" => "production" |
| 562 | + } |
| 563 | + }, |
| 564 | + { |
| 565 | + "name" => "group-two", |
| 566 | + "rules" => { |
| 567 | + "dependency-type" => "development" |
| 568 | + } |
| 569 | + } |
| 570 | + ] |
| 571 | + end |
| 572 | + |
| 573 | + let(:job) do |
| 574 | + instance_double( |
| 575 | + Dependabot::Job, |
| 576 | + dependency_groups: dependency_groups_config, |
| 577 | + source: source, |
| 578 | + dependencies: nil, |
| 579 | + security_updates_only?: false, |
| 580 | + package_manager: "gradle" |
| 581 | + ) |
| 582 | + end |
| 583 | + |
| 584 | + it "raises an error mentioning all affected groups" do |
| 585 | + expect { dependency_group_engine }.to raise_error( |
| 586 | + Dependabot::DependencyGroupEngine::ConfigurationError, |
| 587 | + /Affected groups: group-one, group-two/ |
| 588 | + ) |
| 589 | + end |
| 590 | + end |
| 591 | + |
| 592 | + context "when groups don't use dependency-type with an unsupported package manager" do |
| 593 | + let(:dependency_groups_config) do |
| 594 | + [ |
| 595 | + { |
| 596 | + "name" => "test-group", |
| 597 | + "rules" => { |
| 598 | + "patterns" => ["dummy-*"] |
| 599 | + } |
| 600 | + } |
| 601 | + ] |
| 602 | + end |
| 603 | + |
| 604 | + let(:job) do |
| 605 | + instance_double( |
| 606 | + Dependabot::Job, |
| 607 | + dependency_groups: dependency_groups_config, |
| 608 | + source: source, |
| 609 | + dependencies: nil, |
| 610 | + security_updates_only?: false, |
| 611 | + package_manager: "gradle" |
| 612 | + ) |
| 613 | + end |
| 614 | + |
| 615 | + it "does not raise an error" do |
| 616 | + expect { dependency_group_engine }.not_to raise_error |
| 617 | + end |
| 618 | + end |
| 619 | + end |
483 | 620 | end |
0 commit comments