|
| 1 | +# typed: true |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +require "test_helper" |
| 5 | + |
| 6 | +module Packwerk |
| 7 | + class PackagePathsTest < Minitest::Test |
| 8 | + include RailsApplicationFixtureHelper |
| 9 | + |
| 10 | + setup do |
| 11 | + setup_application_fixture |
| 12 | + end |
| 13 | + |
| 14 | + teardown do |
| 15 | + teardown_application_fixture |
| 16 | + end |
| 17 | + |
| 18 | + test "#all_paths supports a path wildcard" do |
| 19 | + use_template(:skeleton) |
| 20 | + package_paths = PackagePaths.new(".", "**") |
| 21 | + |
| 22 | + assert_includes(package_paths.all_paths, Pathname.new("components/sales/package.yml")) |
| 23 | + assert_includes(package_paths.all_paths, Pathname.new("package.yml")) |
| 24 | + end |
| 25 | + |
| 26 | + test "#all_paths supports a single path as a string" do |
| 27 | + use_template(:skeleton) |
| 28 | + package_paths = PackagePaths.new(".", "components/sales") |
| 29 | + |
| 30 | + assert_equal(package_paths.all_paths, [Pathname.new("components/sales/package.yml")]) |
| 31 | + end |
| 32 | + |
| 33 | + test "#all_paths supports many paths as an array" do |
| 34 | + use_template(:skeleton) |
| 35 | + package_paths = PackagePaths.new(".", ["components/sales", "."]) |
| 36 | + |
| 37 | + assert_equal( |
| 38 | + package_paths.all_paths, |
| 39 | + [ |
| 40 | + Pathname.new("components/sales/package.yml"), |
| 41 | + Pathname.new("package.yml"), |
| 42 | + ] |
| 43 | + ) |
| 44 | + end |
| 45 | + |
| 46 | + test "#all_paths excludes paths inside the gem directory" do |
| 47 | + use_template(:skeleton) |
| 48 | + vendor_package_path = Pathname.new("vendor/cache/gems/example/package.yml") |
| 49 | + |
| 50 | + package_paths = PackagePaths.new(".", "**") |
| 51 | + assert_includes(package_paths.all_paths, vendor_package_path) |
| 52 | + |
| 53 | + Bundler.expects(:bundle_path).once.returns(Rails.root.join("vendor/cache/gems")) |
| 54 | + package_paths = PackagePaths.new(".", "**") |
| 55 | + refute_includes(package_paths.all_paths, vendor_package_path) |
| 56 | + end |
| 57 | + |
| 58 | + test "#all_paths excludes paths in exclude pathspec" do |
| 59 | + use_template(:skeleton) |
| 60 | + vendor_package_path = Pathname.new("vendor/cache/gems/example/package.yml") |
| 61 | + |
| 62 | + package_paths = PackagePaths.new(".", "**") |
| 63 | + assert_includes(package_paths.all_paths, vendor_package_path) |
| 64 | + |
| 65 | + package_paths = PackagePaths.new(".", "**", "vendor/*") |
| 66 | + refute_includes(package_paths.all_paths, vendor_package_path) |
| 67 | + end |
| 68 | + |
| 69 | + test "#all_paths excludes paths in multiple exclude pathspecs" do |
| 70 | + use_template(:skeleton) |
| 71 | + |
| 72 | + vendor_package_path = Pathname.new("vendor/cache/gems/example/package.yml") |
| 73 | + sales_package_path = Pathname.new("components/sales/package.yml") |
| 74 | + |
| 75 | + package_paths = PackagePaths.new(".", "**") |
| 76 | + assert_includes(package_paths.all_paths, vendor_package_path) |
| 77 | + assert_includes(package_paths.all_paths, sales_package_path) |
| 78 | + |
| 79 | + package_paths = PackagePaths.new(".", "**", ["vendor/*", "components/sales/*"]) |
| 80 | + refute_includes(package_paths.all_paths, vendor_package_path) |
| 81 | + refute_includes(package_paths.all_paths, sales_package_path) |
| 82 | + end |
| 83 | + |
| 84 | + test "#all_paths ignores empty excludes" do |
| 85 | + use_template(:skeleton) |
| 86 | + |
| 87 | + assert_equal( |
| 88 | + PackagePaths.new(".", "**").all_paths, |
| 89 | + PackagePaths.new(".", "**", []).all_paths |
| 90 | + ) |
| 91 | + end |
| 92 | + end |
| 93 | +end |
0 commit comments