|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +class Git::Pkgs::TestConfig < Minitest::Test |
| 6 | + include TestHelpers |
| 7 | + |
| 8 | + def setup |
| 9 | + create_test_repo |
| 10 | + Git::Pkgs::Config.reset! |
| 11 | + end |
| 12 | + |
| 13 | + def teardown |
| 14 | + cleanup_test_repo |
| 15 | + Git::Pkgs::Config.reset! |
| 16 | + end |
| 17 | + |
| 18 | + def test_ignored_dirs_returns_empty_array_when_not_configured |
| 19 | + Dir.chdir(@test_dir) do |
| 20 | + assert_equal [], Git::Pkgs::Config.ignored_dirs |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + def test_ignored_dirs_returns_configured_values |
| 25 | + Dir.chdir(@test_dir) do |
| 26 | + system("git config --add pkgs.ignoredDirs third_party", out: File::NULL) |
| 27 | + system("git config --add pkgs.ignoredDirs external", out: File::NULL) |
| 28 | + Git::Pkgs::Config.reset! |
| 29 | + |
| 30 | + assert_equal ["third_party", "external"], Git::Pkgs::Config.ignored_dirs |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + def test_ignored_files_returns_empty_array_when_not_configured |
| 35 | + Dir.chdir(@test_dir) do |
| 36 | + assert_equal [], Git::Pkgs::Config.ignored_files |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + def test_ignored_files_returns_configured_values |
| 41 | + Dir.chdir(@test_dir) do |
| 42 | + system("git config --add pkgs.ignoredFiles test/fixtures/package.json", out: File::NULL) |
| 43 | + Git::Pkgs::Config.reset! |
| 44 | + |
| 45 | + assert_equal ["test/fixtures/package.json"], Git::Pkgs::Config.ignored_files |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + def test_ecosystems_returns_empty_array_when_not_configured |
| 50 | + Dir.chdir(@test_dir) do |
| 51 | + assert_equal [], Git::Pkgs::Config.ecosystems |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + def test_ecosystems_returns_configured_values |
| 56 | + Dir.chdir(@test_dir) do |
| 57 | + system("git config --add pkgs.ecosystems rubygems", out: File::NULL) |
| 58 | + system("git config --add pkgs.ecosystems npm", out: File::NULL) |
| 59 | + Git::Pkgs::Config.reset! |
| 60 | + |
| 61 | + assert_equal ["rubygems", "npm"], Git::Pkgs::Config.ecosystems |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + def test_filter_ecosystem_returns_false_for_local_when_no_ecosystems_configured |
| 66 | + Dir.chdir(@test_dir) do |
| 67 | + refute Git::Pkgs::Config.filter_ecosystem?("rubygems") |
| 68 | + refute Git::Pkgs::Config.filter_ecosystem?("npm") |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + def test_filter_ecosystem_returns_true_for_remote_when_no_ecosystems_configured |
| 73 | + Dir.chdir(@test_dir) do |
| 74 | + assert Git::Pkgs::Config.filter_ecosystem?("carthage") |
| 75 | + assert Git::Pkgs::Config.filter_ecosystem?("clojars") |
| 76 | + assert Git::Pkgs::Config.filter_ecosystem?("hackage") |
| 77 | + assert Git::Pkgs::Config.filter_ecosystem?("hex") |
| 78 | + assert Git::Pkgs::Config.filter_ecosystem?("swiftpm") |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + def test_filter_ecosystem_allows_remote_when_explicitly_enabled |
| 83 | + Dir.chdir(@test_dir) do |
| 84 | + system("git config --add pkgs.ecosystems carthage", out: File::NULL) |
| 85 | + Git::Pkgs::Config.reset! |
| 86 | + |
| 87 | + refute Git::Pkgs::Config.filter_ecosystem?("carthage") |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + def test_filter_ecosystem_returns_false_for_included_ecosystem |
| 92 | + Dir.chdir(@test_dir) do |
| 93 | + system("git config --add pkgs.ecosystems rubygems", out: File::NULL) |
| 94 | + system("git config --add pkgs.ecosystems npm", out: File::NULL) |
| 95 | + Git::Pkgs::Config.reset! |
| 96 | + |
| 97 | + refute Git::Pkgs::Config.filter_ecosystem?("rubygems") |
| 98 | + refute Git::Pkgs::Config.filter_ecosystem?("npm") |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + def test_filter_ecosystem_returns_true_for_excluded_ecosystem |
| 103 | + Dir.chdir(@test_dir) do |
| 104 | + system("git config --add pkgs.ecosystems rubygems", out: File::NULL) |
| 105 | + Git::Pkgs::Config.reset! |
| 106 | + |
| 107 | + assert Git::Pkgs::Config.filter_ecosystem?("npm") |
| 108 | + assert Git::Pkgs::Config.filter_ecosystem?("pypi") |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + def test_filter_ecosystem_is_case_insensitive |
| 113 | + Dir.chdir(@test_dir) do |
| 114 | + system("git config --add pkgs.ecosystems RubyGems", out: File::NULL) |
| 115 | + Git::Pkgs::Config.reset! |
| 116 | + |
| 117 | + refute Git::Pkgs::Config.filter_ecosystem?("rubygems") |
| 118 | + refute Git::Pkgs::Config.filter_ecosystem?("RUBYGEMS") |
| 119 | + end |
| 120 | + end |
| 121 | + |
| 122 | + def test_remote_ecosystem_returns_true_for_remote_ecosystems |
| 123 | + assert Git::Pkgs::Config.remote_ecosystem?("carthage") |
| 124 | + assert Git::Pkgs::Config.remote_ecosystem?("clojars") |
| 125 | + assert Git::Pkgs::Config.remote_ecosystem?("hackage") |
| 126 | + assert Git::Pkgs::Config.remote_ecosystem?("hex") |
| 127 | + assert Git::Pkgs::Config.remote_ecosystem?("swiftpm") |
| 128 | + end |
| 129 | + |
| 130 | + def test_remote_ecosystem_returns_false_for_local_ecosystems |
| 131 | + refute Git::Pkgs::Config.remote_ecosystem?("rubygems") |
| 132 | + refute Git::Pkgs::Config.remote_ecosystem?("npm") |
| 133 | + refute Git::Pkgs::Config.remote_ecosystem?("pypi") |
| 134 | + end |
| 135 | + |
| 136 | + def test_configure_bibliothecary_adds_ignored_dirs |
| 137 | + Dir.chdir(@test_dir) do |
| 138 | + system("git config --add pkgs.ignoredDirs my_vendor", out: File::NULL) |
| 139 | + Git::Pkgs::Config.reset! |
| 140 | + |
| 141 | + original_dirs = Bibliothecary.configuration.ignored_dirs.dup |
| 142 | + Git::Pkgs::Config.configure_bibliothecary |
| 143 | + |
| 144 | + assert_includes Bibliothecary.configuration.ignored_dirs, "my_vendor" |
| 145 | + |
| 146 | + # Clean up |
| 147 | + Bibliothecary.configuration.ignored_dirs = original_dirs |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + def test_configure_bibliothecary_adds_ignored_files |
| 152 | + Dir.chdir(@test_dir) do |
| 153 | + system("git config --add pkgs.ignoredFiles fixtures/Gemfile", out: File::NULL) |
| 154 | + Git::Pkgs::Config.reset! |
| 155 | + |
| 156 | + original_files = Bibliothecary.configuration.ignored_files.dup |
| 157 | + Git::Pkgs::Config.configure_bibliothecary |
| 158 | + |
| 159 | + assert_includes Bibliothecary.configuration.ignored_files, "fixtures/Gemfile" |
| 160 | + |
| 161 | + # Clean up |
| 162 | + Bibliothecary.configuration.ignored_files = original_files |
| 163 | + end |
| 164 | + end |
| 165 | +end |
0 commit comments