Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions tests/unit/release_sandbox_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,53 @@ if [[ "${BASH_VERSINFO[0]}" -eq 3 ]] && [[ "${BASH_VERSINFO[1]}" -lt 1 ]]; then
fi

RELEASE_SCRIPT_DIR=""
FIXTURE_DIR=""

function set_up_before_script() {
RELEASE_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

# Source release.sh to get access to functions
# shellcheck source=/dev/null
source "$RELEASE_SCRIPT_DIR/release.sh"

# Tiny fake project dir: release::sandbox::create tars $(pwd), so running it
# from the repo root copies ~21MB per call. The fixture keeps it to a few KB
# and makes the exclusion tests self-contained (#825). bashunit::temp_dir is
# cleaned by the framework after all workers finish — a manual rm -rf in
# tear_down_after_script would race the parallel workers, which start before
# the file-level teardown runs.
FIXTURE_DIR=$(bashunit::temp_dir "release-fixture")
echo '#!/usr/bin/env bash' >"$FIXTURE_DIR/bashunit"
echo '#!/usr/bin/env bash' >"$FIXTURE_DIR/build.sh"
echo '# Changelog' >"$FIXTURE_DIR/CHANGELOG.md"
mkdir "$FIXTURE_DIR/.git" "$FIXTURE_DIR/.release-state"
echo 'ref: refs/heads/main' >"$FIXTURE_DIR/.git/HEAD"
echo 'state' >"$FIXTURE_DIR/.release-state/state.txt"
}

##########################
# Sandbox mode tests
##########################

function test_sandbox_create_creates_temp_directory() {
local original_dir
original_dir=$(pwd)

cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null

assert_not_empty "$SANDBOX_DIR"
assert_directory_exists "$SANDBOX_DIR"

rm -rf "$SANDBOX_DIR"
cd "$original_dir" || return
}

function test_sandbox_create_copies_project_files() {
local original_dir
original_dir=$(pwd)

cd "$RELEASE_SCRIPT_DIR" || return
cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null

# Check that key files were copied
Expand All @@ -48,10 +70,10 @@ function test_sandbox_create_excludes_git_directory() {
local original_dir
original_dir=$(pwd)

cd "$RELEASE_SCRIPT_DIR" || return
cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null

# .git should NOT be copied
# .git exists in the fixture but should NOT be copied
assert_directory_not_exists "$SANDBOX_DIR/.git"

rm -rf "$SANDBOX_DIR"
Expand All @@ -62,16 +84,13 @@ function test_sandbox_create_excludes_release_state() {
local original_dir
original_dir=$(pwd)

cd "$RELEASE_SCRIPT_DIR" || return

# Create a .release-state directory to test exclusion
mkdir -p .release-state/test
cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null

# .release-state should NOT be copied
# .release-state exists in the fixture but should NOT be copied
assert_directory_not_exists "$SANDBOX_DIR/.release-state"

rm -rf "$SANDBOX_DIR" .release-state
rm -rf "$SANDBOX_DIR"
cd "$original_dir" || return
}

Expand All @@ -83,7 +102,7 @@ function test_sandbox_setup_git_initializes_repo() {
local original_dir
original_dir=$(pwd)

cd "$RELEASE_SCRIPT_DIR" || return
cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null
release::sandbox::setup_git 2>/dev/null

Expand All @@ -102,7 +121,7 @@ function test_sandbox_setup_git_creates_initial_commit() {
local original_dir
original_dir=$(pwd)

cd "$RELEASE_SCRIPT_DIR" || return
cd "$FIXTURE_DIR" || return
release::sandbox::create 2>/dev/null
release::sandbox::setup_git 2>/dev/null

Expand Down
Loading