Files
OpenShell/tasks/scripts/test-snap-install-hook.sh
krishicks 4cd1351e18 fix(test): use portable file mode checks in snap installer tests (#3670)
The snap installer tests added in #3656 checked the gateway config mode
with GNU stat -c, which BSD stat on macOS rejects, so mise run ci failed
locally on macOS. Check the mode with find -perm instead, which matches
the exact mode on both GNU and BSD systems.

Signed-off-by: Kris Hicks <khicks@nvidia.com>
2026-09-24 21:17:12 +00:00

55 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
hook_input=${1:?Usage: test-snap-install-hook.sh <install-hook>}
hook_dir=$(cd "$(dirname "$hook_input")" && pwd)
hook="${hook_dir}/$(basename "$hook_input")"
work=$(mktemp -d "${TMPDIR:-/tmp}/openshell snap install hook.XXXXXX")
trap 'rm -rf "$work"' EXIT
expected="${work}/expected.toml"
cat >"$expected" <<'EOF'
[openshell]
version = 2
[openshell.gateway]
[openshell.gateway.auth]
allow_unauthenticated_users = true
EOF
common="${work}/fresh"
SNAP_COMMON="$common" "$hook"
cmp -s "$expected" "$common/gateway.toml"
if [[ -z $(find "$common/gateway.toml" -perm 600) ]]; then
echo "FAIL: install hook config must be mode 0600" >&2
exit 1
fi
printf '\noperator setting = true\n' >>"$common/gateway.toml"
cp "$common/gateway.toml" "${work}/operator-before"
SNAP_COMMON="$common" "$hook"
cmp -s "${work}/operator-before" "$common/gateway.toml"
common="${work}/broken-link"
mkdir -p "$common"
ln -s "${work}/missing-target" "$common/gateway.toml"
SNAP_COMMON="$common" "$hook"
if [[ $(readlink "$common/gateway.toml") != "${work}/missing-target" ]]; then
echo "FAIL: install hook replaced a broken operator symlink" >&2
exit 1
fi
common="${work}/directory"
mkdir -p "$common/gateway.toml"
SNAP_COMMON="$common" "$hook"
if [[ ! -d "$common/gateway.toml" ]]; then
echo "FAIL: install hook replaced an operator-owned directory" >&2
exit 1
fi
echo "Snap install hook tests passed"