aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorKiyoshi '13k' Murata2017-06-01 04:26:55 -0300
committerKiyoshi '13k' Murata2017-06-01 06:02:50 -0300
commitc4b010b6d7f559350f7c68e7abba51dcf269b8fa (patch)
tree83e2b7d0e1c308b60bb8685d05e3d996c72abf5b /Library
parent63b2eb9ffd1a0131194e99c65e3f0e1e1980ed9b (diff)
downloadbrew-c4b010b6d7f559350f7c68e7abba51dcf269b8fa.tar.bz2
Fix curl invocation in Hbc::DSL::Appcast.
Fixes #2592
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/appcast.rb2
-rw-r--r--Library/Homebrew/test/cask/dsl/appcast_spec.rb74
2 files changed, 75 insertions, 1 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
index e27870622..d302d0946 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
@@ -12,7 +12,7 @@ module Hbc
end
def calculate_checkpoint
- result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, @uri], print_stderr: false)
+ result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false)
checkpoint = if result.success?
processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}m, "")
diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb
new file mode 100644
index 000000000..b8903b1be
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb
@@ -0,0 +1,74 @@
+require "cmd/cask"
+
+describe Hbc::DSL::Appcast do
+ subject { described_class.new(url, params) }
+
+ let(:url) { "http://example.com" }
+ let(:uri) { Hbc::UnderscoreSupportingURI.parse(url) }
+ let(:params) { {} }
+
+ describe "#to_s" do
+ it "returns the parsed URI string" do
+ expect(subject.to_s).to eq("http://example.com")
+ end
+ end
+
+ describe "#to_yaml" do
+ let(:yaml) { [uri, params].to_yaml }
+
+ context "with empty parameters" do
+ it "returns an YAML serialized array composed of the URI and parameters" do
+ expect(subject.to_yaml).to eq(yaml)
+ end
+ end
+
+ context "with checkpoint in parameters" do
+ let(:params) { { checkpoint: "abc123" } }
+
+ it "returns an YAML serialized array composed of the URI and parameters" do
+ expect(subject.to_yaml).to eq(yaml)
+ end
+ end
+ end
+
+ describe "#calculate_checkpoint" do
+ before do
+ expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result)
+ allow(cmd_result).to receive(:success?).and_return(cmd_success)
+ allow(cmd_result).to receive(:stdout).and_return(cmd_stdout)
+ end
+
+ context "when server returns a successful HTTP status" do
+ let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] }
+ let(:cmd_result) { double("Hbc::SystemCommand::Result") }
+ let(:cmd_success) { true }
+ let(:cmd_stdout) { "hello world" }
+
+ it "generates the content digest hash and returns a hash with the command result and the digest hash for the checkpoint" do
+ expected_digest = Digest::SHA2.hexdigest(cmd_stdout)
+ expected_result = {
+ checkpoint: expected_digest,
+ command_result: cmd_result,
+ }
+
+ expect(subject.calculate_checkpoint).to eq(expected_result)
+ end
+ end
+
+ context "when server returns a non-successful HTTP status" do
+ let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] }
+ let(:cmd_result) { double("Hbc::SystemCommand::Result") }
+ let(:cmd_success) { false }
+ let(:cmd_stdout) { "some error message from the server" }
+
+ it "returns a hash with the command result and nil for the checkpoint" do
+ expected_result = {
+ checkpoint: nil,
+ command_result: cmd_result,
+ }
+
+ expect(subject.calculate_checkpoint).to eq(expected_result)
+ end
+ end
+ end
+end