Skip to content

Commit 426040d

Browse files
dikshagupta1agadgil-progress
authored andcommitted
add simple hooks and ext binaries test
1. fix test external binaries 2. add plans for install hooks 3. fix tests_simple_hooks and test_external_binaries 4. update comments Signed-off-by: dikshagupta1 <dikshag@progress.com>
1 parent 6de7dc6 commit 426040d

9 files changed

Lines changed: 150 additions & 7 deletions

File tree

.expeditor/end_to_end.pipeline.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,38 @@ steps:
12961296
env:
12971297
BUILD_PKG_TARGET: aarch64-darwin
12981298

1299+
- label: "[:mac: test_simple_hooks_darwin]"
1300+
command:
1301+
- bash .expeditor/scripts/end_to_end/run_e2e_test_darwin.sh dev test_simple_hooks_darwin
1302+
artifact_paths:
1303+
- "*.log"
1304+
agents:
1305+
queue: 'default-macos-arm64-privileged'
1306+
plugins:
1307+
- chef/anka#v0.7.2:
1308+
vm-name: buildkite-core-14-arm64
1309+
always-pull: true
1310+
wait-network: true
1311+
inherit-environment-vars: true
1312+
env:
1313+
BUILD_PKG_TARGET: aarch64-darwin
1314+
1315+
- label: "[:mac: test_external_binaries_darwin]"
1316+
command:
1317+
- bash .expeditor/scripts/end_to_end/run_e2e_test_darwin.sh dev test_external_binaries_darwin
1318+
artifact_paths:
1319+
- "*.log"
1320+
agents:
1321+
queue: 'default-macos-arm64-privileged'
1322+
plugins:
1323+
- chef/anka#v0.7.2:
1324+
vm-name: buildkite-core-14-arm64
1325+
always-pull: true
1326+
wait-network: true
1327+
inherit-environment-vars: true
1328+
env:
1329+
BUILD_PKG_TARGET: aarch64-darwin
1330+
12991331
- wait
13001332

13011333
- label: "[:habicat: Promote to Acceptance]"

.expeditor/scripts/end_to_end/run_e2e_test_core_darwin.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ function Wait-StopSupervisor($Timeout = 10, $port = 9631) {
9494

9595
# Generate a new unique log file name, given a base name.
9696
#
97-
# The base name should be something descriptive that allows you to
97+
# The base name should be something descriptive that allows us to
9898
# trace a given log file back to the test case that generated it.
9999
#
100100
# This is used instead of the standard `New-TemporaryFile`, since that
101-
# does not seem to allow you to specify any non-random components,
101+
# does not seem to allow us to specify any non-random components,
102102
# which we will need for both correlating outputs to tests, as well as
103103
# easily collecting log outputs in Buildkite.
104104
#
@@ -288,7 +288,7 @@ Function Invoke-BuildAndInstall($PackageName, $RefreshChannel) {
288288
Invoke-Build @PSBoundParameters
289289
. ./results/last_build.ps1
290290
# Use --ignore-install-hook because the install hook interpreter
291-
# (core/busybox-static) is not available for aarch64-darwin.
291+
# (core/busybox-static) is not available for aarch64-darwin.
292292
hab pkg install --ignore-install-hook ./results/$pkg_artifact
293293
# On Linux, the original function runs `hab studio run "rm hooks"` to
294294
# clean up inside the chroot studio (separate from the host filesystem).

.expeditor/scripts/end_to_end/setup_environment_darwin.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export HAB_STUDIO_BACKLINE_PKG
7878
HAB_STUDIO_BACKLINE_PKG="$(cat "$(hab pkg path chef/hab-backline)/IDENT")"
7979
echo "--- HAB_STUDIO_BACKLINE_PKG=${HAB_STUDIO_BACKLINE_PKG}"
8080

81+
# Override the interpreter identity to core/coreutils (installed via
82+
# hab-backline) because core/busybox-static is not available for
83+
# aarch64-darwin. This is needed for install hook execution.
84+
export HAB_INTERPRETER_IDENT="core/coreutils"
85+
8186
echo "--- Installing latest core/powershell from ${HAB_BLDR_URL}, stable channel"
8287
# Try the hab package first, fall back to Homebrew
8388
if sudo -E hab pkg install core/powershell \
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

test/end-to-end/test_pkg_download.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# HAB_TEST_CMD=./target/debug/hab test/end-to-end/test_pkg_download.sh
2121
#
2222
$cacheDir = "test-cache"
23-
# core/gzip is not yet available for aarch64-darwin in LTS-2024; use aarch64-darwin channel on macOS
23+
# use aarch64-darwin channel on macOS
2424
$downloadChannel = if ($IsMacOS) { "aarch64-darwin" } else { "LTS-2024" }
2525

2626
function Test-IdentDownloaded($FilePrefix) {

test/end-to-end/test_pkg_uninstall_darwin.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# macOS-specific pkg uninstall tests.
2-
# Unlike test_pkg_uninstall.ps1, this does NOT require the supervisor or
3-
# hab studio (Invoke-BuildAndInstall). It only uses packages available
4-
# from Builder on the aarch64-darwin channel.
52

63
$pkg = "core/sqlite"
74
$nginxPkg = "core/nginx"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# macOS-specific hooks tests.
2+
# Tests hook extension stripping, hook execution during package install,
3+
# and bad hook extension detection.
4+
# HAB_INTERPRETER_IDENT is set to core/coreutils in setup_environment_darwin.sh
5+
# since core/busybox-static is not available for aarch64-darwin.
6+
7+
Describe "Hook extension stripping and execution" {
8+
BeforeAll {
9+
hab origin key generate $env:HAB_ORIGIN
10+
Invoke-Build hook-extension-plan
11+
. ./results/last_build.ps1
12+
$script:pkgIdent = $pkg_ident
13+
$script:pkgName = ($pkg_ident -split "/")[1]
14+
$script:pkgPrefix = "/hab/pkgs/$pkg_ident"
15+
}
16+
17+
It "strips .sh extension from hook files" {
18+
"$script:pkgPrefix/hooks/install" | Should -Exist
19+
}
20+
21+
It "does not keep the original .sh file" {
22+
Test-Path "$script:pkgPrefix/hooks/install.sh" | Should -Be $false
23+
}
24+
25+
It "runs the install hook successfully on package install" {
26+
# Install the built package without --ignore-install-hook so the hook runs
27+
hab pkg install ./results/$pkg_artifact
28+
"$script:pkgPrefix/INSTALL_HOOK_STATUS" | Should -Exist
29+
Get-Content "$script:pkgPrefix/INSTALL_HOOK_STATUS" | Should -Be "0"
30+
}
31+
32+
It "install hook renders templates and produces stdout" {
33+
$logPath = "/hab/svc/$($script:pkgName)/logs/install.stdout.log"
34+
$logPath | Should -Exist
35+
Get-Content $logPath | Should -Contain "install hook $($script:pkgName)"
36+
}
37+
}
38+
39+
Describe "Bad hook extension plan" {
40+
It "fails when there are multiple extensions for the same hook" {
41+
hab pkg build test/fixtures/bad-hook-extension-plan
42+
$LASTEXITCODE | Should -Not -Be 0
43+
}
44+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "install hook {{pkg.name}}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pkg_name="simple-hooks"
2+
pkg_origin="habitat-testing"
3+
pkg_version="0.0.0"
4+
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
5+
6+
do_build() {
7+
return 0
8+
}
9+
10+
do_install() {
11+
return 0
12+
}

0 commit comments

Comments
 (0)