2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2021-01-22 12:22:24 -08:00
|
|
|
# frozen_string_literal: true
|
2020-08-08 07:10:48 +05:30
|
|
|
|
|
|
|
require "livecheck/livecheck"
|
|
|
|
|
|
|
|
describe Homebrew::Livecheck do
|
|
|
|
subject(:livecheck) { described_class }
|
|
|
|
|
2021-01-13 09:30:50 -05:00
|
|
|
let(:cask_url) { "https://brew.sh/test-0.0.1.dmg" }
|
|
|
|
let(:head_url) { "https://github.com/Homebrew/brew.git" }
|
|
|
|
let(:homepage_url) { "https://brew.sh" }
|
|
|
|
let(:livecheck_url) { "https://formulae.brew.sh/api/formula/ruby.json" }
|
|
|
|
let(:stable_url) { "https://brew.sh/test-0.0.1.tgz" }
|
2021-01-12 15:00:49 -05:00
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
let(:f) do
|
|
|
|
formula("test") do
|
|
|
|
desc "Test formula"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
2022-05-18 15:36:12 -04:00
|
|
|
url "https://brew.sh/test-0.0.1.tgz", using: :homebrew_curl
|
2021-01-13 09:30:50 -05:00
|
|
|
head "https://github.com/Homebrew/brew.git"
|
2020-08-08 07:10:48 +05:30
|
|
|
|
|
|
|
livecheck do
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://formulae.brew.sh/api/formula/ruby.json"
|
2020-08-29 02:18:18 +05:30
|
|
|
regex(/"stable":"(\d+(?:\.\d+)+)"/i)
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-19 22:26:37 -05:00
|
|
|
let(:c) do
|
|
|
|
Cask::CaskLoader.load(+<<-RUBY)
|
|
|
|
cask "test" do
|
|
|
|
version "0.0.1,2"
|
|
|
|
|
2022-05-18 15:36:12 -04:00
|
|
|
url "https://brew.sh/test-0.0.1.dmg", using: :homebrew_curl
|
2020-12-19 22:26:37 -05:00
|
|
|
name "Test"
|
|
|
|
desc "Test cask"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
2020-12-19 22:26:37 -05:00
|
|
|
|
|
|
|
livecheck do
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://formulae.brew.sh/api/formula/ruby.json"
|
2020-12-19 22:26:37 -05:00
|
|
|
regex(/"stable":"(\d+(?:\.\d+)+)"/i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2021-08-13 16:29:06 -04:00
|
|
|
let(:f_duplicate_urls) do
|
|
|
|
formula("test_duplicate_urls") do
|
|
|
|
desc "Test formula with a duplicate URL"
|
|
|
|
homepage "https://github.com/Homebrew/brew.git"
|
|
|
|
url "https://brew.sh/test-0.0.1.tgz"
|
|
|
|
head "https://github.com/Homebrew/brew.git"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-19 11:21:29 -04:00
|
|
|
describe "::resolve_livecheck_reference" do
|
|
|
|
context "when a formula/cask has a livecheck block without formula/cask methods" do
|
|
|
|
it "returns [nil, []]" do
|
|
|
|
expect(livecheck.resolve_livecheck_reference(f)).to eq([nil, []])
|
|
|
|
expect(livecheck.resolve_livecheck_reference(c)).to eq([nil, []])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
describe "::formula_name" do
|
|
|
|
it "returns the name of the formula" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.formula_name(f)).to eq("test")
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the full name" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.formula_name(f, full_name: true)).to eq("test")
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-02 12:24:21 -07:00
|
|
|
describe "::cask_name" do
|
|
|
|
it "returns the token of the cask" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.cask_name(c)).to eq("test")
|
2020-09-02 12:24:21 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the full name of the cask" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.cask_name(c, full_name: true)).to eq("test")
|
2020-09-02 12:24:21 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
describe "::status_hash" do
|
|
|
|
it "returns a hash containing the livecheck status" do
|
2020-12-14 14:30:36 +01:00
|
|
|
expect(livecheck.status_hash(f, "error", ["Unable to get versions"]))
|
2020-08-08 07:10:48 +05:30
|
|
|
.to eq({
|
2021-02-11 13:24:19 +00:00
|
|
|
formula: "test",
|
|
|
|
status: "error",
|
|
|
|
messages: ["Unable to get versions"],
|
|
|
|
meta: {
|
|
|
|
livecheckable: true,
|
|
|
|
},
|
|
|
|
})
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-12 15:00:49 -05:00
|
|
|
describe "::livecheck_url_to_string" do
|
|
|
|
let(:f_livecheck_url) do
|
|
|
|
formula("test_livecheck_url") do
|
|
|
|
desc "Test Livecheck URL formula"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/test-0.0.1.tgz"
|
|
|
|
head "https://github.com/Homebrew/brew.git"
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:c_livecheck_url) do
|
|
|
|
Cask::CaskLoader.load(+<<-RUBY)
|
|
|
|
cask "test_livecheck_url" do
|
|
|
|
version "0.0.1,2"
|
|
|
|
|
2021-01-13 09:30:50 -05:00
|
|
|
url "https://brew.sh/test-0.0.1.dmg"
|
2021-01-12 15:00:49 -05:00
|
|
|
name "Test"
|
|
|
|
desc "Test Livecheck URL cask"
|
2021-01-13 09:30:50 -05:00
|
|
|
homepage "https://brew.sh"
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a URL string when given a livecheck_url string" do
|
2021-01-13 09:30:50 -05:00
|
|
|
f_livecheck_url.livecheck.url(livecheck_url)
|
|
|
|
expect(livecheck.livecheck_url_to_string(livecheck_url, f_livecheck_url)).to eq(livecheck_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a URL symbol when given a valid livecheck_url symbol" do
|
|
|
|
f_livecheck_url.livecheck.url(:head)
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(head_url, f_livecheck_url)).to eq(head_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
|
|
|
|
f_livecheck_url.livecheck.url(:homepage)
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(homepage_url, f_livecheck_url)).to eq(homepage_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
|
|
|
|
c_livecheck_url.livecheck.url(:homepage)
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(homepage_url, c_livecheck_url)).to eq(homepage_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
|
|
|
|
f_livecheck_url.livecheck.url(:stable)
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(stable_url, f_livecheck_url)).to eq(stable_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
|
|
|
|
c_livecheck_url.livecheck.url(:url)
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.livecheck_url_to_string(cask_url, c_livecheck_url)).to eq(cask_url)
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when not given a string or valid symbol" do
|
2022-03-01 00:36:05 +00:00
|
|
|
expect(livecheck.livecheck_url_to_string(nil, f_livecheck_url)).to be_nil
|
|
|
|
expect(livecheck.livecheck_url_to_string(nil, c_livecheck_url)).to be_nil
|
|
|
|
expect(livecheck.livecheck_url_to_string(:invalid_symbol, f_livecheck_url)).to be_nil
|
|
|
|
expect(livecheck.livecheck_url_to_string(:invalid_symbol, c_livecheck_url)).to be_nil
|
2021-01-12 15:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-08 07:10:48 +05:30
|
|
|
describe "::checkable_urls" do
|
|
|
|
it "returns the list of URLs to check" do
|
2021-02-04 15:41:29 -05:00
|
|
|
expect(livecheck.checkable_urls(f)).to eq([stable_url, head_url, homepage_url])
|
2021-01-13 09:30:50 -05:00
|
|
|
expect(livecheck.checkable_urls(c)).to eq([cask_url, homepage_url])
|
2021-08-13 16:29:06 -04:00
|
|
|
expect(livecheck.checkable_urls(f_duplicate_urls)).to eq([stable_url, head_url])
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-23 23:22:41 -05:00
|
|
|
describe "::use_homebrew_curl?" do
|
2022-05-18 15:36:12 -04:00
|
|
|
it "uses brewed curl if called for by the download URL" do
|
2021-11-23 23:22:41 -05:00
|
|
|
expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false)
|
2022-05-18 15:36:12 -04:00
|
|
|
expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(true)
|
|
|
|
expect(livecheck.use_homebrew_curl?(f, stable_url)).to be(true)
|
2021-11-23 23:22:41 -05:00
|
|
|
expect(livecheck.use_homebrew_curl?(c, livecheck_url)).to be(false)
|
2022-05-18 15:36:12 -04:00
|
|
|
expect(livecheck.use_homebrew_curl?(c, homepage_url)).to be(true)
|
|
|
|
expect(livecheck.use_homebrew_curl?(c, cask_url)).to be(true)
|
2021-11-23 23:22:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-27 22:46:06 +05:30
|
|
|
describe "::preprocess_url" do
|
2020-11-11 11:52:58 -05:00
|
|
|
let(:github_git_url_with_extension) { "https://github.com/Homebrew/brew.git" }
|
2020-08-29 02:18:18 +05:30
|
|
|
|
2020-11-26 13:34:16 -05:00
|
|
|
it "returns the unmodified URL for an unparseable URL" do
|
|
|
|
# Modeled after the `head` URL in the `ncp` formula
|
|
|
|
expect(livecheck.preprocess_url(":something:cvs:@cvs.brew.sh:/cvs"))
|
|
|
|
.to eq(":something:cvs:@cvs.brew.sh:/cvs")
|
|
|
|
end
|
|
|
|
|
2020-11-11 11:52:58 -05:00
|
|
|
it "returns the unmodified URL for a GitHub URL ending in .git" do
|
|
|
|
expect(livecheck.preprocess_url(github_git_url_with_extension))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a GitHub URL not ending in .git" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.com/Homebrew/brew"))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the unmodified URL for a GitHub /releases/latest URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.com/Homebrew/brew/releases/latest"))
|
|
|
|
.to eq("https://github.com/Homebrew/brew/releases/latest")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a GitHub AWS URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.s3.amazonaws.com/downloads/Homebrew/brew/1.0.0.tar.gz"))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a github.com/downloads/... URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.com/downloads/Homebrew/brew/1.0.0.tar.gz"))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a GitHub tag archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.com/Homebrew/brew/archive/1.0.0.tar.gz"))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a GitHub release archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://github.com/Homebrew/brew/releases/download/1.0.0/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq(github_git_url_with_extension)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a gitlab.com archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://gitlab.com/Homebrew/brew/-/archive/1.0.0/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://gitlab.com/Homebrew/brew.git")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a self-hosted GitLab archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://brew.sh/Homebrew/brew/-/archive/1.0.0/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://brew.sh/Homebrew/brew.git")
|
2020-08-27 22:46:06 +05:30
|
|
|
end
|
2020-11-26 09:50:00 -05:00
|
|
|
|
|
|
|
it "returns the Git repository URL for a Codeberg archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://codeberg.org/Homebrew/brew/archive/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://codeberg.org/Homebrew/brew.git")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a Gitea archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://gitea.com/Homebrew/brew/archive/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://gitea.com/Homebrew/brew.git")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for an Opendev archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://opendev.org/Homebrew/brew/archive/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://opendev.org/Homebrew/brew.git")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a tildegit archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://tildegit.org/Homebrew/brew/archive/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://tildegit.org/Homebrew/brew.git")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the Git repository URL for a LOL Git archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://lolg.it/Homebrew/brew/archive/brew-1.0.0.tar.gz"))
|
|
|
|
.to eq("https://lolg.it/Homebrew/brew.git")
|
|
|
|
end
|
2020-11-26 13:34:16 -05:00
|
|
|
|
|
|
|
it "returns the Git repository URL for a sourcehut archive URL" do
|
|
|
|
expect(livecheck.preprocess_url("https://git.sr.ht/~Homebrew/brew/archive/1.0.0.tar.gz"))
|
|
|
|
.to eq("https://git.sr.ht/~Homebrew/brew")
|
|
|
|
end
|
2020-08-27 22:46:06 +05:30
|
|
|
end
|
2020-08-08 07:10:48 +05:30
|
|
|
end
|