| 1 | |
| 2 | |
| 3 | |
| 4 | package asifutil |
| 5 | |
| 6 | import ( |
| 7 | "testing" |
| 8 | |
| 9 | "gotest.tools/v3/assert" |
| 10 | ) |
| 11 | |
| 12 | func TestParseDiskutilImageAttachOutput(t *testing.T) { |
| 13 | const input = `<?xml version="1.0" encoding="UTF-8"?> |
| 14 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 15 | <plist version="1.0"> |
| 16 | <dict> |
| 17 | <key>system-entities</key> |
| 18 | <array> |
| 19 | <dict> |
| 20 | <key>content-hint</key> |
| 21 | <string>GUID_partition_scheme</string> |
| 22 | <key>dev-entry</key> |
| 23 | <string>disk4</string> |
| 24 | <key>size</key> |
| 25 | <integer>107374182400</integer> |
| 26 | </dict> |
| 27 | <dict> |
| 28 | <key>content-hint</key> |
| 29 | <string>Apple_APFS_ISC</string> |
| 30 | <key>dev-entry</key> |
| 31 | <string>disk4s1</string> |
| 32 | <key>size</key> |
| 33 | <integer>524288000</integer> |
| 34 | </dict> |
| 35 | <dict> |
| 36 | <key>content-hint</key> |
| 37 | <string>Apple_APFS_Container</string> |
| 38 | <key>dev-entry</key> |
| 39 | <string>disk5</string> |
| 40 | <key>size</key> |
| 41 | <integer>524288000</integer> |
| 42 | </dict> |
| 43 | <dict> |
| 44 | <key>content-hint</key> |
| 45 | <string>Apple_APFS_Volume</string> |
| 46 | <key>dev-entry</key> |
| 47 | <string>disk5s1</string> |
| 48 | <key>filesystem-name</key> |
| 49 | <string>APFS</string> |
| 50 | <key>filesystem-type</key> |
| 51 | <string>apfs</string> |
| 52 | <key>role</key> |
| 53 | <string>Preboot</string> |
| 54 | <key>size</key> |
| 55 | <integer>524288000</integer> |
| 56 | <key>volume-name</key> |
| 57 | <string>iSCPreboot</string> |
| 58 | </dict> |
| 59 | <dict> |
| 60 | <key>content-hint</key> |
| 61 | <string>Apple_APFS_Volume</string> |
| 62 | <key>dev-entry</key> |
| 63 | <string>disk5s2</string> |
| 64 | <key>filesystem-name</key> |
| 65 | <string>APFS</string> |
| 66 | <key>filesystem-type</key> |
| 67 | <string>apfs</string> |
| 68 | <key>role</key> |
| 69 | <string>XART</string> |
| 70 | <key>size</key> |
| 71 | <integer>524288000</integer> |
| 72 | <key>volume-name</key> |
| 73 | <string>xART</string> |
| 74 | </dict> |
| 75 | <dict> |
| 76 | <key>content-hint</key> |
| 77 | <string>Apple_APFS_Volume</string> |
| 78 | <key>dev-entry</key> |
| 79 | <string>disk5s3</string> |
| 80 | <key>filesystem-name</key> |
| 81 | <string>APFS</string> |
| 82 | <key>filesystem-type</key> |
| 83 | <string>apfs</string> |
| 84 | <key>role</key> |
| 85 | <string>Hardware</string> |
| 86 | <key>size</key> |
| 87 | <integer>524288000</integer> |
| 88 | <key>volume-name</key> |
| 89 | <string>Hardware</string> |
| 90 | </dict> |
| 91 | <dict> |
| 92 | <key>content-hint</key> |
| 93 | <string>Apple_APFS_Volume</string> |
| 94 | <key>dev-entry</key> |
| 95 | <string>disk5s4</string> |
| 96 | <key>filesystem-name</key> |
| 97 | <string>APFS</string> |
| 98 | <key>filesystem-type</key> |
| 99 | <string>apfs</string> |
| 100 | <key>role</key> |
| 101 | <string>Recovery</string> |
| 102 | <key>size</key> |
| 103 | <integer>524288000</integer> |
| 104 | <key>volume-name</key> |
| 105 | <string>Recovery</string> |
| 106 | </dict> |
| 107 | <dict> |
| 108 | <key>content-hint</key> |
| 109 | <string>Apple_APFS</string> |
| 110 | <key>dev-entry</key> |
| 111 | <string>disk4s2</string> |
| 112 | <key>size</key> |
| 113 | <integer>101481185280</integer> |
| 114 | </dict> |
| 115 | <dict> |
| 116 | <key>content-hint</key> |
| 117 | <string>Apple_APFS_Container</string> |
| 118 | <key>dev-entry</key> |
| 119 | <string>disk7</string> |
| 120 | <key>size</key> |
| 121 | <integer>101481185280</integer> |
| 122 | </dict> |
| 123 | <dict> |
| 124 | <key>content-hint</key> |
| 125 | <string>Apple_APFS_Volume</string> |
| 126 | <key>dev-entry</key> |
| 127 | <string>disk7s1</string> |
| 128 | <key>filesystem-name</key> |
| 129 | <string>APFS</string> |
| 130 | <key>filesystem-type</key> |
| 131 | <string>apfs</string> |
| 132 | <key>role</key> |
| 133 | <string>System</string> |
| 134 | <key>size</key> |
| 135 | <integer>101481185280</integer> |
| 136 | <key>volume-group</key> |
| 137 | <string>4B262719-EFC8-4B4D-8831-8AD57E005B59</string> |
| 138 | <key>volume-name</key> |
| 139 | <string>Macintosh HD</string> |
| 140 | </dict> |
| 141 | <dict> |
| 142 | <key>content-hint</key> |
| 143 | <string>Apple_APFS_Volume</string> |
| 144 | <key>dev-entry</key> |
| 145 | <string>disk7s2</string> |
| 146 | <key>filesystem-name</key> |
| 147 | <string>APFS</string> |
| 148 | <key>filesystem-type</key> |
| 149 | <string>apfs</string> |
| 150 | <key>role</key> |
| 151 | <string>Preboot</string> |
| 152 | <key>size</key> |
| 153 | <integer>101481185280</integer> |
| 154 | <key>volume-name</key> |
| 155 | <string>Preboot</string> |
| 156 | </dict> |
| 157 | <dict> |
| 158 | <key>content-hint</key> |
| 159 | <string>Apple_APFS_Volume</string> |
| 160 | <key>dev-entry</key> |
| 161 | <string>disk7s3</string> |
| 162 | <key>filesystem-name</key> |
| 163 | <string>APFS</string> |
| 164 | <key>filesystem-type</key> |
| 165 | <string>apfs</string> |
| 166 | <key>role</key> |
| 167 | <string>Recovery</string> |
| 168 | <key>size</key> |
| 169 | <integer>101481185280</integer> |
| 170 | <key>volume-name</key> |
| 171 | <string>Recovery</string> |
| 172 | </dict> |
| 173 | <dict> |
| 174 | <key>content-hint</key> |
| 175 | <string>Apple_APFS_Volume</string> |
| 176 | <key>dev-entry</key> |
| 177 | <string>disk7s4</string> |
| 178 | <key>filesystem-name</key> |
| 179 | <string>APFS</string> |
| 180 | <key>filesystem-type</key> |
| 181 | <string>apfs</string> |
| 182 | <key>role</key> |
| 183 | <string>Update</string> |
| 184 | <key>size</key> |
| 185 | <integer>101481185280</integer> |
| 186 | <key>volume-name</key> |
| 187 | <string>Update</string> |
| 188 | </dict> |
| 189 | <dict> |
| 190 | <key>content-hint</key> |
| 191 | <string>Apple_APFS_Volume</string> |
| 192 | <key>dev-entry</key> |
| 193 | <string>disk7s5</string> |
| 194 | <key>filesystem-name</key> |
| 195 | <string>APFS</string> |
| 196 | <key>filesystem-type</key> |
| 197 | <string>apfs</string> |
| 198 | <key>role</key> |
| 199 | <string>Data</string> |
| 200 | <key>size</key> |
| 201 | <integer>101481185280</integer> |
| 202 | <key>volume-group</key> |
| 203 | <string>4B262719-EFC8-4B4D-8831-8AD57E005B59</string> |
| 204 | <key>volume-name</key> |
| 205 | <string>Data</string> |
| 206 | </dict> |
| 207 | <dict> |
| 208 | <key>content-hint</key> |
| 209 | <string>Apple_APFS_Volume</string> |
| 210 | <key>dev-entry</key> |
| 211 | <string>disk7s6</string> |
| 212 | <key>filesystem-name</key> |
| 213 | <string>APFS</string> |
| 214 | <key>filesystem-type</key> |
| 215 | <string>apfs</string> |
| 216 | <key>role</key> |
| 217 | <string>VM</string> |
| 218 | <key>size</key> |
| 219 | <integer>101481185280</integer> |
| 220 | <key>volume-name</key> |
| 221 | <string>VM</string> |
| 222 | </dict> |
| 223 | <dict> |
| 224 | <key>content-hint</key> |
| 225 | <string>Apple_APFS_Recovery</string> |
| 226 | <key>dev-entry</key> |
| 227 | <string>disk4s3</string> |
| 228 | <key>size</key> |
| 229 | <integer>5368668160</integer> |
| 230 | </dict> |
| 231 | <dict> |
| 232 | <key>content-hint</key> |
| 233 | <string>Apple_APFS_Container</string> |
| 234 | <key>dev-entry</key> |
| 235 | <string>disk6</string> |
| 236 | <key>size</key> |
| 237 | <integer>5368668160</integer> |
| 238 | </dict> |
| 239 | <dict> |
| 240 | <key>content-hint</key> |
| 241 | <string>Apple_APFS_Volume</string> |
| 242 | <key>dev-entry</key> |
| 243 | <string>disk6s1</string> |
| 244 | <key>filesystem-name</key> |
| 245 | <string>APFS</string> |
| 246 | <key>filesystem-type</key> |
| 247 | <string>apfs</string> |
| 248 | <key>role</key> |
| 249 | <string>Recovery</string> |
| 250 | <key>size</key> |
| 251 | <integer>5368668160</integer> |
| 252 | <key>volume-name</key> |
| 253 | <string>Recovery</string> |
| 254 | </dict> |
| 255 | <dict> |
| 256 | <key>content-hint</key> |
| 257 | <string>Apple_APFS_Volume</string> |
| 258 | <key>dev-entry</key> |
| 259 | <string>disk6s2</string> |
| 260 | <key>filesystem-name</key> |
| 261 | <string>APFS</string> |
| 262 | <key>filesystem-type</key> |
| 263 | <string>apfs</string> |
| 264 | <key>role</key> |
| 265 | <string>Update</string> |
| 266 | <key>size</key> |
| 267 | <integer>5368668160</integer> |
| 268 | <key>volume-name</key> |
| 269 | <string>Update</string> |
| 270 | </dict> |
| 271 | </array> |
| 272 | </dict> |
| 273 | </plist> |
| 274 | ` |
| 275 | expected := &AttachedDisk{ |
| 276 | Disk: "disk4", |
| 277 | Container: "disk4s2", |
| 278 | Data: "disk7s5", |
| 279 | } |
| 280 | res, err := parseDiskutilImageAttachOutput(input) |
| 281 | assert.NilError(t, err) |
| 282 | assert.DeepEqual(t, res, expected) |
| 283 | } |