Move part of parser_test to system_command_result_spec.
This commit is contained in:
parent
1e1a8bf626
commit
fef96f0ba8
@ -0,0 +1,49 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Hbc::SystemCommand::Result do
|
||||
describe "::_parse_plist" do
|
||||
let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) }
|
||||
let(:hdiutil_output) {
|
||||
<<-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"?>
|
||||
<!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_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 "ignores garbage output before xml starts" do
|
||||
parsed = described_class._parse_plist(command, hdiutil_output)
|
||||
|
||||
expect(parsed.keys).to eq(["system-entities"])
|
||||
expect(parsed["system-entities"].length).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2,51 +2,51 @@ require "test_helper"
|
||||
|
||||
describe Plist do
|
||||
it "parses some hdiutil output okay" do
|
||||
hdiutil_output = <<-HDIUTILOUTPUT
|
||||
<?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>
|
||||
HDIUTILOUTPUT
|
||||
hdiutil_output = <<-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
|
||||
|
||||
parsed = Plist.parse_xml(hdiutil_output)
|
||||
|
||||
@ -59,47 +59,6 @@ describe Plist do
|
||||
]
|
||||
end
|
||||
|
||||
it "can ignore garbage output before xml starts" do
|
||||
hdiutil_output = <<-HDIUTILOUTPUT
|
||||
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"?>
|
||||
<!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_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>
|
||||
HDIUTILOUTPUT
|
||||
|
||||
parsed = Plist.parse_xml(hdiutil_output)
|
||||
|
||||
parsed.keys.must_equal ["system-entities"]
|
||||
parsed["system-entities"].length.must_equal 1
|
||||
end
|
||||
|
||||
it "does not choke on empty input" do
|
||||
Plist.parse_xml("").must_equal {}
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user