Add baseline test for Cask#to_h
Also, added a test for loading JSON files in the cask loader.
This commit is contained in:
parent
c19017c6bd
commit
9087afba74
@ -41,6 +41,12 @@ describe Cask::Cask, :cask do
|
|||||||
expect(c.token).to eq("local-caffeine")
|
expect(c.token).to eq("local-caffeine")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns an instance of the Cask from a JSON file" do
|
||||||
|
c = Cask::CaskLoader.load("#{tap_path}/caffeine.json")
|
||||||
|
expect(c).to be_a(described_class)
|
||||||
|
expect(c.token).to eq("caffeine")
|
||||||
|
end
|
||||||
|
|
||||||
it "returns an instance of the Cask from a URL" do
|
it "returns an instance of the Cask from a URL" do
|
||||||
c = Cask::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb")
|
c = Cask::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb")
|
||||||
expect(c).to be_a(described_class)
|
expect(c).to be_a(described_class)
|
||||||
@ -49,9 +55,7 @@ describe Cask::Cask, :cask do
|
|||||||
|
|
||||||
it "raises an error when failing to download a Cask from a URL" do
|
it "raises an error when failing to download a Cask from a URL" do
|
||||||
expect {
|
expect {
|
||||||
url = "file://#{tap_path}/Casks/notacask.rb"
|
Cask::CaskLoader.load("file://#{tap_path}/Casks/notacask.rb")
|
||||||
|
|
||||||
Cask::CaskLoader.load(url)
|
|
||||||
}.to raise_error(Cask::CaskUnavailableError)
|
}.to raise_error(Cask::CaskUnavailableError)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -212,6 +216,33 @@ describe Cask::Cask, :cask do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#to_h" do
|
||||||
|
let(:json_file) { "#{TEST_FIXTURE_DIR}/cask/everything.json" }
|
||||||
|
let(:expected_json) { File.read(json_file).strip }
|
||||||
|
|
||||||
|
context "when loaded from cask file" do
|
||||||
|
it "returns expected hash" do
|
||||||
|
hash = Cask::CaskLoader.load("everything").to_h
|
||||||
|
|
||||||
|
expect(hash).to be_a(Hash)
|
||||||
|
expect(JSON.pretty_generate(hash)).to eq(expected_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when loaded from json file" do
|
||||||
|
it "returns expected hash" do
|
||||||
|
expect(Homebrew::API::Cask).not_to receive(:fetch_source)
|
||||||
|
hash = Cask::CaskLoader::FromAPILoader
|
||||||
|
.new("everything", from_json: JSON.parse(expected_json))
|
||||||
|
.load(config: nil)
|
||||||
|
.to_h
|
||||||
|
|
||||||
|
expect(hash).to be_a(Hash)
|
||||||
|
expect(JSON.pretty_generate(hash)).to eq(expected_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#to_hash_with_variations" do
|
describe "#to_hash_with_variations" do
|
||||||
let!(:original_macos_version) { MacOS.full_version.to_s }
|
let!(:original_macos_version) { MacOS.full_version.to_s }
|
||||||
let(:expected_versions_variations) {
|
let(:expected_versions_variations) {
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
# Used to test cask hash generation.
|
||||||
|
cask "everything" do
|
||||||
|
version "1.2.3"
|
||||||
|
|
||||||
|
language "en", default: true do
|
||||||
|
sha256 "c64c05bdc0be845505d6e55e69e696a7f50d40846e76155f0c85d5ff5e7bbb84"
|
||||||
|
"en-US"
|
||||||
|
end
|
||||||
|
language "eo" do
|
||||||
|
sha256 "e8ffa07370a7fb7e1696b04c269e01d3459725965a32facdd54629a95d148908"
|
||||||
|
"eo"
|
||||||
|
end
|
||||||
|
|
||||||
|
url "https://cachefly.everything.app/releases/Everything_#{version}.zip",
|
||||||
|
user_agent: :fake,
|
||||||
|
cookies: { "ALL" => "1234" }
|
||||||
|
name "Everything"
|
||||||
|
desc "Little bit of everything"
|
||||||
|
homepage "https://www.everything.app/"
|
||||||
|
|
||||||
|
auto_updates true
|
||||||
|
conflicts_with formula: "nothing"
|
||||||
|
depends_on cask: "something"
|
||||||
|
container type: :naked
|
||||||
|
|
||||||
|
app "Everything.app"
|
||||||
|
installer script: {
|
||||||
|
executable: "~/just/another/path/install.sh",
|
||||||
|
args: ["--mode=silent"],
|
||||||
|
sudo: true,
|
||||||
|
print_stderr: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall launchctl: "com.every.thing.agent",
|
||||||
|
delete: ["/Library/EverythingHelperTools"],
|
||||||
|
kext: "com.every.thing.driver",
|
||||||
|
signal: [
|
||||||
|
["TERM", "com.every.thing.controller#{version.major}"],
|
||||||
|
["TERM", "com.every.thing.bin"],
|
||||||
|
]
|
||||||
|
|
||||||
|
zap trash: [
|
||||||
|
"~/.everything",
|
||||||
|
"~/Library/Everything",
|
||||||
|
]
|
||||||
|
|
||||||
|
caveats "Installing everything might take a while..."
|
||||||
|
end
|
||||||
42
Library/Homebrew/test/support/fixtures/cask/caffeine.json
Normal file
42
Library/Homebrew/test/support/fixtures/cask/caffeine.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"token": "caffeine",
|
||||||
|
"full_token": "caffeine",
|
||||||
|
"tap": null,
|
||||||
|
"name": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"desc": null,
|
||||||
|
"homepage": "https://brew.sh/",
|
||||||
|
"url": "https://www.example.com/cask/caffeine.zip",
|
||||||
|
"appcast": null,
|
||||||
|
"version": "1.2.3",
|
||||||
|
"versions": {
|
||||||
|
},
|
||||||
|
"installed": null,
|
||||||
|
"outdated": false,
|
||||||
|
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"app": [
|
||||||
|
"Caffeine.app"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"zap": [
|
||||||
|
{
|
||||||
|
"trash": "/$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"caveats": null,
|
||||||
|
"depends_on": {
|
||||||
|
},
|
||||||
|
"conflicts_with": null,
|
||||||
|
"container": null,
|
||||||
|
"auto_updates": null,
|
||||||
|
"tap_git_head": null,
|
||||||
|
"languages": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
99
Library/Homebrew/test/support/fixtures/cask/everything.json
Normal file
99
Library/Homebrew/test/support/fixtures/cask/everything.json
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
{
|
||||||
|
"token": "everything",
|
||||||
|
"full_token": "everything",
|
||||||
|
"tap": "homebrew/cask",
|
||||||
|
"name": [
|
||||||
|
"Everything"
|
||||||
|
],
|
||||||
|
"desc": "Little bit of everything",
|
||||||
|
"homepage": "https://www.everything.app/",
|
||||||
|
"url": "https://cachefly.everything.app/releases/Everything_1.2.3.zip",
|
||||||
|
"url_specs": {
|
||||||
|
"cookies": {
|
||||||
|
"ALL": "1234"
|
||||||
|
},
|
||||||
|
"user_agent": ":fake"
|
||||||
|
},
|
||||||
|
"appcast": null,
|
||||||
|
"version": "1.2.3",
|
||||||
|
"versions": {
|
||||||
|
},
|
||||||
|
"installed": null,
|
||||||
|
"outdated": false,
|
||||||
|
"sha256": "c64c05bdc0be845505d6e55e69e696a7f50d40846e76155f0c85d5ff5e7bbb84",
|
||||||
|
"artifacts": [
|
||||||
|
{
|
||||||
|
"uninstall": [
|
||||||
|
{
|
||||||
|
"launchctl": "com.every.thing.agent",
|
||||||
|
"delete": [
|
||||||
|
"/Library/EverythingHelperTools"
|
||||||
|
],
|
||||||
|
"kext": "com.every.thing.driver",
|
||||||
|
"signal": [
|
||||||
|
[
|
||||||
|
"TERM",
|
||||||
|
"com.every.thing.controller1"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"TERM",
|
||||||
|
"com.every.thing.bin"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"installer": [
|
||||||
|
{
|
||||||
|
"script": {
|
||||||
|
"executable": "~/just/another/path/install.sh",
|
||||||
|
"args": [
|
||||||
|
"--mode=silent"
|
||||||
|
],
|
||||||
|
"sudo": true,
|
||||||
|
"print_stderr": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"app": [
|
||||||
|
"Everything.app"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"zap": [
|
||||||
|
{
|
||||||
|
"trash": [
|
||||||
|
"~/.everything",
|
||||||
|
"~/Library/Everything"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"caveats": "Installing everything might take a while...\n\neverything requires a kernel extension to work.\nIf the installation fails, retry after you enable it in:\n System Preferences → Security & Privacy → General\n\nFor more information, refer to vendor documentation or this Apple Technical Note:\n https://developer.apple.com/library/content/technotes/tn2459/_index.html\n",
|
||||||
|
"depends_on": {
|
||||||
|
"cask": [
|
||||||
|
"something"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"conflicts_with": {
|
||||||
|
"formula": [
|
||||||
|
"nothing"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"container": {
|
||||||
|
"type": "naked"
|
||||||
|
},
|
||||||
|
"auto_updates": true,
|
||||||
|
"tap_git_head": null,
|
||||||
|
"languages": [
|
||||||
|
"en",
|
||||||
|
"eo"
|
||||||
|
],
|
||||||
|
"ruby_source_checksum": {
|
||||||
|
"sha256": "b2707d1952f02c3fa566b7ad2a707a847a959d36f51d3dee642dbe5deec12f27"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user