|
1 | | -# typed: strong |
| 1 | +# typed: false |
2 | 2 | # frozen_string_literal: true |
3 | 3 |
|
4 | 4 | require "spec_helper" |
5 | 5 | require "dependabot/pre_commit/metadata_finder" |
6 | 6 | require_common_spec "metadata_finders/shared_examples_for_metadata_finders" |
| 7 | + |
| 8 | +RSpec.describe Dependabot::PreCommit::MetadataFinder do |
| 9 | + subject(:finder) do |
| 10 | + described_class.new(dependency: dependency, credentials: credentials) |
| 11 | + end |
| 12 | + |
| 13 | + let(:credentials) do |
| 14 | + [{ |
| 15 | + "type" => "git_source", |
| 16 | + "host" => "github.com", |
| 17 | + "username" => "x-access-token", |
| 18 | + "password" => "token" |
| 19 | + }] |
| 20 | + end |
| 21 | + let(:dependency_source) do |
| 22 | + { |
| 23 | + type: "git", |
| 24 | + url: "https://github.com/pre-commit/pre-commit-hooks", |
| 25 | + ref: "v4.4.0", |
| 26 | + branch: nil |
| 27 | + } |
| 28 | + end |
| 29 | + let(:dependency_name) { "https://github.com/pre-commit/pre-commit-hooks" } |
| 30 | + let(:dependency) do |
| 31 | + Dependabot::Dependency.new( |
| 32 | + name: dependency_name, |
| 33 | + version: "v4.4.0", |
| 34 | + requirements: [{ |
| 35 | + requirement: nil, |
| 36 | + groups: [], |
| 37 | + file: ".pre-commit-config.yaml", |
| 38 | + source: dependency_source |
| 39 | + }], |
| 40 | + package_manager: "pre_commit" |
| 41 | + ) |
| 42 | + end |
| 43 | + |
| 44 | + it_behaves_like "a dependency metadata finder" |
| 45 | + |
| 46 | + describe "#source_url" do |
| 47 | + subject(:source_url) { finder.source_url } |
| 48 | + |
| 49 | + context "when dealing with a git source" do |
| 50 | + let(:dependency_source) do |
| 51 | + { |
| 52 | + type: "git", |
| 53 | + url: "https://github.com/pre-commit/pre-commit-hooks", |
| 54 | + ref: "v4.4.0", |
| 55 | + branch: nil |
| 56 | + } |
| 57 | + end |
| 58 | + |
| 59 | + it { is_expected.to eq("https://github.com/pre-commit/pre-commit-hooks") } |
| 60 | + end |
| 61 | + |
| 62 | + context "when dealing with a subdependency (no requirements)" do |
| 63 | + let(:dependency) do |
| 64 | + Dependabot::Dependency.new( |
| 65 | + name: dependency_name, |
| 66 | + version: "v4.4.0", |
| 67 | + requirements: [], |
| 68 | + package_manager: "pre_commit" |
| 69 | + ) |
| 70 | + end |
| 71 | + |
| 72 | + it { is_expected.to eq("https://github.com/pre-commit/pre-commit-hooks") } |
| 73 | + end |
| 74 | + |
| 75 | + context "when dealing with a gitlab source" do |
| 76 | + let(:dependency_name) { "https://gitlab.com/pycqa/flake8" } |
| 77 | + let(:dependency_source) do |
| 78 | + { |
| 79 | + type: "git", |
| 80 | + url: "https://gitlab.com/pycqa/flake8", |
| 81 | + ref: "v5.0.0", |
| 82 | + branch: nil |
| 83 | + } |
| 84 | + end |
| 85 | + |
| 86 | + it { is_expected.to eq("https://gitlab.com/pycqa/flake8") } |
| 87 | + end |
| 88 | + end |
| 89 | +end |
0 commit comments