Merge Plist spec with SystemCommand::Result spec.
This commit is contained in:
parent
fa34aa2a21
commit
c97f8dc8b1
@ -37,8 +37,6 @@ require "hbc/verify"
|
|||||||
require "hbc/version"
|
require "hbc/version"
|
||||||
require "utils"
|
require "utils"
|
||||||
|
|
||||||
require "vendor/plist/plist"
|
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
include Locations
|
include Locations
|
||||||
include Scopes
|
include Scopes
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
require "open3"
|
require "open3"
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
|
require "vendor/plist/plist"
|
||||||
|
|
||||||
require "extend/io"
|
require "extend/io"
|
||||||
|
|
||||||
@ -167,16 +168,6 @@ module Hbc
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
xml
|
xml
|
||||||
rescue Plist::ParseError => e
|
|
||||||
raise CaskError, <<-EOS
|
|
||||||
Error parsing plist output from command.
|
|
||||||
command was:
|
|
||||||
#{command.utf8_inspect}
|
|
||||||
error was:
|
|
||||||
#{e}
|
|
||||||
output we attempted to parse:
|
|
||||||
#{output}
|
|
||||||
EOS
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,22 +1,37 @@
|
|||||||
|
require "hbc/system_command"
|
||||||
|
|
||||||
describe Hbc::SystemCommand::Result do
|
describe Hbc::SystemCommand::Result do
|
||||||
describe "::_parse_plist" do
|
describe "::_parse_plist" do
|
||||||
|
subject { described_class._parse_plist(command, input) }
|
||||||
let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) }
|
let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) }
|
||||||
let(:hdiutil_output) {
|
let(:plist) {
|
||||||
<<-EOS.undent
|
<<-EOS.undent
|
||||||
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 <not> explode!
|
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>system-entities</key>
|
<key>system-entities</key>
|
||||||
<array>
|
<array>
|
||||||
|
<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>
|
||||||
<dict>
|
<dict>
|
||||||
<key>content-hint</key>
|
<key>content-hint</key>
|
||||||
<string>Apple_HFS</string>
|
<string>Apple_HFS</string>
|
||||||
@ -37,11 +52,44 @@ describe Hbc::SystemCommand::Result do
|
|||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
it "ignores garbage output before xml starts" do
|
context "when output contains garbage" do
|
||||||
parsed = described_class._parse_plist(command, hdiutil_output)
|
let(:input) {
|
||||||
|
<<-EOS.undent
|
||||||
|
Hello there! I am in no way XML am I?!?!
|
||||||
|
|
||||||
expect(parsed.keys).to eq(["system-entities"])
|
That's a little silly... you were expexting XML here!
|
||||||
expect(parsed["system-entities"].length).to eq(1)
|
|
||||||
|
What is a parser to do?
|
||||||
|
|
||||||
|
Hopefully <not> 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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,75 +0,0 @@
|
|||||||
require "spec_helper"
|
|
||||||
|
|
||||||
describe Plist do
|
|
||||||
subject { described_class.parse_xml(input) }
|
|
||||||
|
|
||||||
describe "::parse_xml" do
|
|
||||||
context "given a hdiutil output as input" do
|
|
||||||
let(:input) {
|
|
||||||
<<-EOS.undent
|
|
||||||
<?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>
|
|
||||||
<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>
|
|
||||||
<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
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
|
||||||
%w[
|
|
||||||
/dev/disk3s1
|
|
||||||
/dev/disk3
|
|
||||||
/dev/disk3s2
|
|
||||||
],
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "given an empty input" do
|
|
||||||
let(:input) { "" }
|
|
||||||
|
|
||||||
it { is_expected.to be_nil }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user