2020-08-08 07:16:06 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-07-28 13:20:12 -04:00
|
|
|
require "livecheck/strategy"
|
2020-08-08 07:16:06 +05:30
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe Homebrew::Livecheck::Strategy::Bitbucket do
|
2020-08-08 07:16:06 +05:30
|
|
|
subject(:bitbucket) { described_class }
|
|
|
|
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:bitbucket_urls) do
|
2021-07-28 13:20:12 -04:00
|
|
|
{
|
|
|
|
get: "https://bitbucket.org/abc/def/get/1.2.3.tar.gz",
|
|
|
|
downloads: "https://bitbucket.org/abc/def/downloads/ghi-1.2.3.tar.gz",
|
|
|
|
}
|
2023-03-08 23:14:46 +00:00
|
|
|
end
|
2020-08-08 07:16:06 +05:30
|
|
|
let(:non_bitbucket_url) { "https://brew.sh/test" }
|
|
|
|
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:generated) do
|
2021-07-28 13:20:12 -04:00
|
|
|
{
|
|
|
|
get: {
|
|
|
|
url: "https://bitbucket.org/abc/def/downloads/?tab=tags",
|
2023-05-19 10:51:49 -04:00
|
|
|
regex: /<td[^>]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?</im,
|
2021-07-28 13:20:12 -04:00
|
|
|
},
|
|
|
|
downloads: {
|
|
|
|
url: "https://bitbucket.org/abc/def/downloads/",
|
|
|
|
regex: /href=.*?ghi-v?(\d+(?:\.\d+)+)\.t/i,
|
|
|
|
},
|
|
|
|
}
|
2023-03-08 23:14:46 +00:00
|
|
|
end
|
2021-07-28 13:20:12 -04:00
|
|
|
|
2020-08-08 07:16:06 +05:30
|
|
|
describe "::match?" do
|
2021-08-10 17:39:11 -04:00
|
|
|
it "returns true for a Bitbucket URL" do
|
2021-07-28 13:20:12 -04:00
|
|
|
expect(bitbucket.match?(bitbucket_urls[:get])).to be true
|
|
|
|
expect(bitbucket.match?(bitbucket_urls[:downloads])).to be true
|
2020-08-08 07:16:06 +05:30
|
|
|
end
|
|
|
|
|
2021-08-10 17:39:11 -04:00
|
|
|
it "returns false for a non-Bitbucket URL" do
|
2020-08-08 07:16:06 +05:30
|
|
|
expect(bitbucket.match?(non_bitbucket_url)).to be false
|
|
|
|
end
|
|
|
|
end
|
2021-07-28 13:20:12 -04:00
|
|
|
|
|
|
|
describe "::generate_input_values" do
|
|
|
|
it "returns a hash containing url and regex for a Bitbucket URL" do
|
|
|
|
expect(bitbucket.generate_input_values(bitbucket_urls[:get])).to eq(generated[:get])
|
|
|
|
expect(bitbucket.generate_input_values(bitbucket_urls[:downloads])).to eq(generated[:downloads])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an empty hash for a non-Bitbucket URL" do
|
|
|
|
expect(bitbucket.generate_input_values(non_bitbucket_url)).to eq({})
|
|
|
|
end
|
|
|
|
end
|
2020-08-08 07:16:06 +05:30
|
|
|
end
|