|
| 1 | +# macOS-specific external binaries tests. |
| 2 | +# Tests that hab can find and execute binaries from installed packages. |
| 3 | +# Container and Tar exporters are not compiled for macOS, so we test |
| 4 | +# hab pkg exec instead, which is the underlying mechanism for running |
| 5 | +# external package binaries. |
| 6 | + |
| 7 | +$channel = "aarch64-darwin" |
| 8 | + |
| 9 | +Describe "`hab` correctly executes external binaries" { |
| 10 | + BeforeAll { |
| 11 | + hab pkg install core/gzip --channel $channel |
| 12 | + } |
| 13 | + |
| 14 | + It "`hab pkg exec` runs gzip from the package" { |
| 15 | + # Cannot use --version/--help/-V because clap intercepts those flags |
| 16 | + # before they reach the actual binary via execvp(). |
| 17 | + # Instead, compress a file and verify the output exists. |
| 18 | + "hello habitat" | Set-Content -Path /tmp/hab_test_gzip_input.txt |
| 19 | + hab pkg exec core/gzip gzip /tmp/hab_test_gzip_input.txt |
| 20 | + $LASTEXITCODE | Should -Be 0 |
| 21 | + "/tmp/hab_test_gzip_input.txt.gz" | Should -Exist |
| 22 | + Remove-Item -Force /tmp/hab_test_gzip_input.txt.gz |
| 23 | + } |
| 24 | + |
| 25 | + It "`hab pkg exec` can decompress data" { |
| 26 | + # Verify gzip decompression works via pipe (gzip -d reads stdin) |
| 27 | + "test data" | Set-Content -Path /tmp/hab_test_gzip2.txt |
| 28 | + hab pkg exec core/gzip gzip /tmp/hab_test_gzip2.txt |
| 29 | + hab pkg exec core/gzip gzip -d /tmp/hab_test_gzip2.txt.gz |
| 30 | + $LASTEXITCODE | Should -Be 0 |
| 31 | + "/tmp/hab_test_gzip2.txt" | Should -Exist |
| 32 | + Get-Content /tmp/hab_test_gzip2.txt | Should -Be "test data" |
| 33 | + Remove-Item -Force /tmp/hab_test_gzip2.txt |
| 34 | + } |
| 35 | + |
| 36 | + It "`hab pkg exec` with nonexistent package fails" { |
| 37 | + hab pkg exec core/nonexistent-pkg-12345 some-binary 2>&1 |
| 38 | + $LASTEXITCODE | Should -Not -Be 0 |
| 39 | + } |
| 40 | + |
| 41 | + It "`hab pkg exec` with nonexistent binary fails" { |
| 42 | + hab pkg exec core/gzip nonexistent-binary-12345 2>&1 |
| 43 | + $LASTEXITCODE | Should -Not -Be 0 |
| 44 | + } |
| 45 | + |
| 46 | + It "`hab pkg export` with bad exporter fails gracefully" { |
| 47 | + hab pkg export a_bad_exporter --help 2>&1 |
| 48 | + $LASTEXITCODE | Should -Not -Be 0 |
| 49 | + } |
| 50 | +} |
0 commit comments