require "hbc/system_command"
describe Hbc::SystemCommand::Result, :cask do
describe "::_parse_plist" do
subject { described_class._parse_plist(command, input) }
let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) }
let(:plist) {
<<~EOS
system-entities
content-hint
Apple_partition_map
dev-entry
/dev/disk3s1
potentially-mountable
unmapped-content-hint
Apple_partition_map
content-hint
Apple_partition_scheme
dev-entry
/dev/disk3
potentially-mountable
unmapped-content-hint
Apple_partition_scheme
content-hint
Apple_HFS
dev-entry
/dev/disk3s2
mount-point
/private/tmp/dmg.BhfS2g
potentially-mountable
unmapped-content-hint
Apple_HFS
volume-kind
hfs
EOS
}
context "when output contains garbage" do
let(:input) {
<<~EOS
Hello there! I am in no way XML am I?!?!
That's a little silly... you were expexting XML here!
What is a parser to do?
Hopefully explode!
#{plist}
EOS
}
it "ignores garbage before xml" do
expect(subject.keys).to eq(["system-entities"])
expect(subject["system-entities"].length).to eq(3)
end
end
context "given a hdiutil output as input" do
let(:input) { plist }
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
context "given an empty input" do
let(:input) { "" }
it "raises an error" do
expect { subject }.to raise_error(Hbc::CaskError, /Empty plist input/)
end
end
end
end