2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
require_relative "shared_examples/invalid_option"
|
2020-08-18 00:23:23 +01:00
|
|
|
require "cask/auditor"
|
2017-10-03 10:49:58 +02:00
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Cmd::Audit, :cask do
|
2019-02-03 13:03:16 +01:00
|
|
|
let(:cask) { Cask::Cask.new("cask") }
|
2020-07-28 09:08:37 +02:00
|
|
|
let(:result) { { warnings: Set.new, errors: Set.new } }
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
it_behaves_like "a command that handles invalid options"
|
|
|
|
|
2017-02-08 11:58:34 +01:00
|
|
|
describe "selection of Casks to audit" do
|
|
|
|
it "audits all Casks if no tokens are given" do
|
2018-09-06 08:29:14 +02:00
|
|
|
allow(Cask::Cask).to receive(:to_a).and_return([cask, cask])
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-07-28 09:08:37 +02:00
|
|
|
expect(Cask::Auditor).to receive(:audit).twice.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
described_class.run
|
2017-02-08 11:58:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "audits specified Casks if tokens are given" do
|
|
|
|
cask_token = "nice-app"
|
2018-09-06 08:29:14 +02:00
|
|
|
expect(Cask::CaskLoader).to receive(:load).with(cask_token).and_return(cask)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
2020-08-01 02:30:46 +02:00
|
|
|
.with(cask, quarantine: true)
|
2020-07-28 09:08:37 +02:00
|
|
|
.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
described_class.run(cask_token)
|
2017-02-08 11:58:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "does not pass anything if no flags are specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, quarantine: true)
|
|
|
|
.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken")
|
|
|
|
end
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `audit_download` if the `--download` flag is specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, audit_download: true, quarantine: true)
|
|
|
|
.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--download")
|
2017-02-08 11:58:34 +01:00
|
|
|
end
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `audit_token_conflicts` if the `--token-conflicts` flag is specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, audit_token_conflicts: true, quarantine: true)
|
|
|
|
.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--token-conflicts")
|
|
|
|
end
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-09-04 04:14:37 +02:00
|
|
|
it "passes `audit_strict` if the `--strict` flag is specified" do
|
2020-08-01 02:30:46 +02:00
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
2020-09-04 04:14:37 +02:00
|
|
|
.with(cask, audit_strict: true, quarantine: true)
|
2020-08-01 02:30:46 +02:00
|
|
|
.and_return(result)
|
2017-02-08 11:58:34 +01:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--strict")
|
2017-02-08 11:58:34 +01:00
|
|
|
end
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `audit_online` if the `--online` flag is specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
2020-09-04 04:14:37 +02:00
|
|
|
.with(cask, audit_online: true, quarantine: true)
|
2020-08-01 02:30:46 +02:00
|
|
|
.and_return(result)
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--online")
|
|
|
|
end
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-09-04 04:14:37 +02:00
|
|
|
it "passes `audit_new_cask` if the `--new-cask` flag is specified" do
|
2020-08-01 02:30:46 +02:00
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
2020-09-04 04:14:37 +02:00
|
|
|
.with(cask, audit_new_cask: true, quarantine: true)
|
2020-08-01 02:30:46 +02:00
|
|
|
.and_return(result)
|
|
|
|
|
|
|
|
described_class.run("casktoken", "--new-cask")
|
2020-04-23 21:16:17 +02:00
|
|
|
end
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `language` if the `--language` flag is specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, quarantine: true, language: ["de-AT"])
|
|
|
|
.and_return(result)
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--language=de-AT")
|
|
|
|
end
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `quarantine` if the `--no-quarantine` flag is specified" do
|
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, quarantine: false)
|
|
|
|
.and_return(result)
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken", "--no-quarantine")
|
2020-04-23 21:16:17 +02:00
|
|
|
end
|
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
it "passes `quarantine` if the `--no-quarantine` flag is in HOMEBREW_CASK_OPTS" do
|
|
|
|
ENV["HOMEBREW_CASK_OPTS"] = "--no-quarantine"
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
|
|
expect(Cask::Auditor).to receive(:audit)
|
|
|
|
.with(cask, quarantine: false)
|
|
|
|
.and_return(result)
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
described_class.run("casktoken")
|
2020-04-23 21:16:17 +02:00
|
|
|
end
|
2017-02-08 11:58:34 +01:00
|
|
|
end
|