Add tests
Check for the following: - Tap migration rename to core tap can be loaded by short name - Tap migration rename to core tap can be loaded by long name - Tap migration renam that clashes with existing core tap short name is ignored in favor of loading the cask/formula from the core tap
This commit is contained in:
parent
10aa981209
commit
fb3b13e3c3
@ -14,12 +14,14 @@ RSpec.describe Cask::CaskLoader::FromAPILoader, :cask do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
allow(Homebrew::API::Cask)
|
allow(Homebrew::API::Cask)
|
||||||
.to receive(:all_casks)
|
.to receive_messages(all_casks: casks_from_api_hash, all_renames: {})
|
||||||
.and_return(casks_from_api_hash)
|
|
||||||
|
# The call to `Cask::CaskLoader.load` above sets the Tap cache prematurely.
|
||||||
|
Tap.clear_cache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".can_load?" do
|
describe ".try_new" do
|
||||||
include_context "with API setup", "test-opera"
|
include_context "with API setup", "test-opera"
|
||||||
|
|
||||||
context "when not using the API", :no_api do
|
context "when not using the API", :no_api do
|
||||||
@ -34,16 +36,64 @@ RSpec.describe Cask::CaskLoader::FromAPILoader, :cask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns a loader for valid token" do
|
it "returns a loader for valid token" do
|
||||||
expect(described_class.try_new(token)).not_to be_nil
|
expect(described_class.try_new(token))
|
||||||
|
.to be_a(described_class)
|
||||||
|
.and have_attributes(token:)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a loader for valid full name" do
|
it "returns a loader for valid full name" do
|
||||||
expect(described_class.try_new("homebrew/cask/#{token}")).not_to be_nil
|
expect(described_class.try_new("homebrew/cask/#{token}"))
|
||||||
|
.to be_a(described_class)
|
||||||
|
.and have_attributes(token:)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil for full name with invalid tap" do
|
it "returns nil for full name with invalid tap" do
|
||||||
expect(described_class.try_new("homebrew/foo/#{token}")).to be_nil
|
expect(described_class.try_new("homebrew/foo/#{token}")).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with core tap migration renames" do
|
||||||
|
let(:foo_tap) { Tap.fetch("homebrew", "foo") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
foo_tap.path.mkpath
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
FileUtils.rm_rf foo_tap.path
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the core cask if the short name clashes with a tap migration rename" do
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{token}": "homebrew/cask/#{token}-v2" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(Cask::CaskLoader::FromNameLoader.try_new(token))
|
||||||
|
.to be_a(Cask::CaskLoader::FromNameLoader)
|
||||||
|
.and have_attributes(token:)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the tap migration rename by old token" do
|
||||||
|
old_token = "#{token}-old"
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{old_token}": "homebrew/cask/#{token}" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(Cask::CaskLoader::FromNameLoader.try_new(old_token))
|
||||||
|
.to be_a(described_class)
|
||||||
|
.and have_attributes(token:)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the tap migration rename by old full name" do
|
||||||
|
old_token = "#{token}-old"
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{old_token}": "homebrew/cask/#{token}" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(Cask::CaskLoader::FromTapLoader.try_new("#{foo_tap}/#{old_token}"))
|
||||||
|
.to be_a(described_class)
|
||||||
|
.and have_attributes(token:)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -383,6 +383,7 @@ RSpec.describe Formulary do
|
|||||||
# avoid unnecessary network calls
|
# avoid unnecessary network calls
|
||||||
allow(Homebrew::API::Formula).to receive_messages(all_aliases: {}, all_renames: {})
|
allow(Homebrew::API::Formula).to receive_messages(all_aliases: {}, all_renames: {})
|
||||||
allow(CoreTap.instance).to receive(:tap_migrations).and_return({})
|
allow(CoreTap.instance).to receive(:tap_migrations).and_return({})
|
||||||
|
allow(CoreCaskTap.instance).to receive(:tap_migrations).and_return({})
|
||||||
|
|
||||||
# don't try to load/fetch gcc/glibc
|
# don't try to load/fetch gcc/glibc
|
||||||
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
||||||
@ -482,6 +483,51 @@ RSpec.describe Formulary do
|
|||||||
expect(formula.deps.count).to eq 5
|
expect(formula.deps.count).to eq 5
|
||||||
expect(formula.deps.map(&:name).include?("uses_from_macos_dep")).to be true
|
expect(formula.deps.map(&:name).include?("uses_from_macos_dep")).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with core tap migration renames" do
|
||||||
|
let(:foo_tap) { Tap.fetch("homebrew", "foo") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(Homebrew::API::Formula).to receive(:all_formulae).and_return formula_json_contents
|
||||||
|
foo_tap.path.mkpath
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
FileUtils.rm_rf foo_tap.path
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the core formula if the short name clashes with a tap migration rename" do
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{formula_name}": "homebrew/core/#{formula_name}-v2" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(described_class::FromNameLoader.try_new(formula_name))
|
||||||
|
.to be_a(described_class::FromNameLoader)
|
||||||
|
.and have_attributes(name: formula_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the tap migration rename by old formula_name" do
|
||||||
|
old_formula_name = "#{formula_name}-old"
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{old_formula_name}": "homebrew/core/#{formula_name}" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(described_class::FromNameLoader.try_new(old_formula_name))
|
||||||
|
.to be_a(described_class::FromAPILoader)
|
||||||
|
.and have_attributes(name: formula_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the tap migration rename by old full name" do
|
||||||
|
old_formula_name = "#{formula_name}-old"
|
||||||
|
(foo_tap.path/"tap_migrations.json").write <<~JSON
|
||||||
|
{ "#{old_formula_name}": "homebrew/core/#{formula_name}" }
|
||||||
|
JSON
|
||||||
|
|
||||||
|
expect(described_class::FromTapLoader.try_new("#{foo_tap}/#{old_formula_name}"))
|
||||||
|
.to be_a(described_class::FromAPILoader)
|
||||||
|
.and have_attributes(name: formula_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user