2017-02-28 16:31:25 +01:00
|
|
|
require "hbc/system_command"
|
|
|
|
|
2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::SystemCommand::Result, :cask do
|
2018-07-05 09:31:29 +02:00
|
|
|
describe "#plist" do
|
|
|
|
subject { described_class.new(command, stdout, "", 0).plist }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
let(:command) { ["/usr/bin/true"] }
|
|
|
|
let(:garbage) {
|
|
|
|
<<~EOS
|
|
|
|
Hello there! I am in no way XML am I?!?!
|
|
|
|
|
|
|
|
That's a little silly... you were expecting XML here!
|
|
|
|
|
|
|
|
What is a parser to do?
|
|
|
|
|
|
|
|
Hopefully <not> explode!
|
|
|
|
EOS
|
|
|
|
}
|
2017-02-28 16:31:25 +01:00
|
|
|
let(:plist) {
|
2017-10-15 02:28:32 +02:00
|
|
|
<<~EOS
|
2016-08-24 00:41:50 +02:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>system-entities</key>
|
|
|
|
<array>
|
2017-02-28 16:31:25 +01:00
|
|
|
<dict>
|
|
|
|
<key>content-hint</key>
|
|
|
|
<string>Apple_partition_map</string>
|
|
|
|
<key>dev-entry</key>
|
|
|
|
<string>/dev/disk3s1</string>
|
|
|
|
<key>potentially-mountable</key>
|
|
|
|
<false/>
|
|
|
|
<key>unmapped-content-hint</key>
|
|
|
|
<string>Apple_partition_map</string>
|
|
|
|
</dict>
|
|
|
|
<dict>
|
|
|
|
<key>content-hint</key>
|
|
|
|
<string>Apple_partition_scheme</string>
|
|
|
|
<key>dev-entry</key>
|
|
|
|
<string>/dev/disk3</string>
|
|
|
|
<key>potentially-mountable</key>
|
|
|
|
<false/>
|
|
|
|
<key>unmapped-content-hint</key>
|
|
|
|
<string>Apple_partition_scheme</string>
|
|
|
|
</dict>
|
2016-08-24 00:41:50 +02:00
|
|
|
<dict>
|
|
|
|
<key>content-hint</key>
|
|
|
|
<string>Apple_HFS</string>
|
|
|
|
<key>dev-entry</key>
|
|
|
|
<string>/dev/disk3s2</string>
|
|
|
|
<key>mount-point</key>
|
|
|
|
<string>/private/tmp/dmg.BhfS2g</string>
|
|
|
|
<key>potentially-mountable</key>
|
|
|
|
<true/>
|
|
|
|
<key>unmapped-content-hint</key>
|
|
|
|
<string>Apple_HFS</string>
|
|
|
|
<key>volume-kind</key>
|
|
|
|
<string>hfs</string>
|
|
|
|
</dict>
|
|
|
|
</array>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
}
|
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
context "when stdout contains garbage before XML" do
|
|
|
|
let(:stdout) {
|
2017-10-15 02:28:32 +02:00
|
|
|
<<~EOS
|
2018-07-05 09:31:29 +02:00
|
|
|
#{garbage}
|
|
|
|
#{plist}
|
|
|
|
EOS
|
|
|
|
}
|
2017-02-28 16:31:25 +01:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
it "ignores garbage" do
|
|
|
|
expect(subject["system-entities"].length).to eq(3)
|
|
|
|
end
|
2017-02-28 16:31:25 +01:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
context "when verbose" do
|
|
|
|
before(:each) do
|
|
|
|
allow(ARGV).to receive(:verbose?).and_return(true)
|
|
|
|
end
|
2017-02-28 16:31:25 +01:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
it "warns about garbage" do
|
|
|
|
expect { subject }
|
|
|
|
.to output(a_string_containing(garbage)).to_stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-28 16:31:25 +01:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
context "when stdout contains garbage after XML" do
|
|
|
|
let(:stdout) {
|
|
|
|
<<~EOS
|
2017-02-28 16:31:25 +01:00
|
|
|
#{plist}
|
2018-07-05 09:31:29 +02:00
|
|
|
#{garbage}
|
2017-02-28 16:31:25 +01:00
|
|
|
EOS
|
|
|
|
}
|
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
it "ignores garbage" do
|
2017-02-28 16:31:25 +01:00
|
|
|
expect(subject["system-entities"].length).to eq(3)
|
|
|
|
end
|
2018-07-05 09:31:29 +02:00
|
|
|
|
|
|
|
context "when verbose" do
|
|
|
|
before(:each) do
|
|
|
|
allow(ARGV).to receive(:verbose?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "warns about garbage" do
|
|
|
|
expect { subject }
|
|
|
|
.to output(a_string_containing(garbage)).to_stderr
|
|
|
|
end
|
|
|
|
end
|
2017-02-28 16:31:25 +01:00
|
|
|
end
|
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
context "given a hdiutil stdout" do
|
|
|
|
let(:stdout) { plist }
|
2017-02-28 16:31:25 +01:00
|
|
|
|
|
|
|
it "successfully parses it" do
|
|
|
|
expect(subject.keys).to eq(["system-entities"])
|
|
|
|
expect(subject["system-entities"].length).to eq(3)
|
|
|
|
expect(subject["system-entities"].map { |e| e["dev-entry"] })
|
|
|
|
.to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
context "when the stdout of the command is empty" do
|
|
|
|
let(:stdout) { "" }
|
2016-08-24 00:41:50 +02:00
|
|
|
|
2018-07-05 09:31:29 +02:00
|
|
|
it "returns nil" do
|
|
|
|
expect(subject).to be nil
|
2017-02-28 16:31:25 +01:00
|
|
|
end
|
2016-08-24 00:41:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|