|
| 1 | +require "hbc/system_command" |
| 2 | + |
1 | 3 | describe Hbc::SystemCommand::Result do |
2 | 4 | describe "::_parse_plist" do |
| 5 | + subject { described_class._parse_plist(command, input) } |
3 | 6 | let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) } |
4 | | - let(:hdiutil_output) { |
| 7 | + let(:plist) { |
5 | 8 | <<-EOS.undent |
6 | | - Hello there! I am in no way XML am I?!?! |
7 | | -
|
8 | | - That's a little silly... you were expexting XML here! |
9 | | -
|
10 | | - What is a parser to do? |
11 | | -
|
12 | | - Hopefully <not> explode! |
13 | | -
|
14 | 9 | <?xml version="1.0" encoding="UTF-8"?> |
15 | 10 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
16 | 11 | <plist version="1.0"> |
17 | 12 | <dict> |
18 | 13 | <key>system-entities</key> |
19 | 14 | <array> |
| 15 | + <dict> |
| 16 | + <key>content-hint</key> |
| 17 | + <string>Apple_partition_map</string> |
| 18 | + <key>dev-entry</key> |
| 19 | + <string>/dev/disk3s1</string> |
| 20 | + <key>potentially-mountable</key> |
| 21 | + <false/> |
| 22 | + <key>unmapped-content-hint</key> |
| 23 | + <string>Apple_partition_map</string> |
| 24 | + </dict> |
| 25 | + <dict> |
| 26 | + <key>content-hint</key> |
| 27 | + <string>Apple_partition_scheme</string> |
| 28 | + <key>dev-entry</key> |
| 29 | + <string>/dev/disk3</string> |
| 30 | + <key>potentially-mountable</key> |
| 31 | + <false/> |
| 32 | + <key>unmapped-content-hint</key> |
| 33 | + <string>Apple_partition_scheme</string> |
| 34 | + </dict> |
20 | 35 | <dict> |
21 | 36 | <key>content-hint</key> |
22 | 37 | <string>Apple_HFS</string> |
|
37 | 52 | EOS |
38 | 53 | } |
39 | 54 |
|
40 | | - it "ignores garbage output before xml starts" do |
41 | | - parsed = described_class._parse_plist(command, hdiutil_output) |
| 55 | + context "when output contains garbage" do |
| 56 | + let(:input) { |
| 57 | + <<-EOS.undent |
| 58 | + Hello there! I am in no way XML am I?!?! |
| 59 | +
|
| 60 | + That's a little silly... you were expexting XML here! |
| 61 | +
|
| 62 | + What is a parser to do? |
| 63 | +
|
| 64 | + Hopefully <not> explode! |
| 65 | +
|
| 66 | + #{plist} |
| 67 | + EOS |
| 68 | + } |
| 69 | + |
| 70 | + it "ignores garbage before xml" do |
| 71 | + expect(subject.keys).to eq(["system-entities"]) |
| 72 | + expect(subject["system-entities"].length).to eq(3) |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context "given a hdiutil output as input" do |
| 77 | + let(:input) { plist } |
| 78 | + |
| 79 | + it "successfully parses it" do |
| 80 | + expect(subject.keys).to eq(["system-entities"]) |
| 81 | + expect(subject["system-entities"].length).to eq(3) |
| 82 | + expect(subject["system-entities"].map { |e| e["dev-entry"] }) |
| 83 | + .to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"]) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + context "given an empty input" do |
| 88 | + let(:input) { "" } |
42 | 89 |
|
43 | | - expect(parsed.keys).to eq(["system-entities"]) |
44 | | - expect(parsed["system-entities"].length).to eq(1) |
| 90 | + it "raises an error" do |
| 91 | + expect { subject }.to raise_error(Hbc::CaskError, /Empty plist input/) |
| 92 | + end |
45 | 93 | end |
46 | 94 | end |
47 | 95 | end |
0 commit comments