Test Directory
This directory is used for testing wild-cloud functionality using the Bats testing framework.
Contents
test_helper.bash- Shared Bats test setup and utilitiestest_helper/- Bats framework extensions (bats-support, bats-assert)bats/- Bats core framework (git submodule)fixtures/- Test data and sample configuration files*.bats- Bats test files for different componentsrun_bats_tests.sh- Runs the complete Bats test suitetmp/- Temporary test projects (auto-created/cleaned)
Test Files
test_common_functions.bats
Tests the core functions in wild-common.sh:
find_wc_home()- Project root detectioninit_wild_env()- Environment setupcheck_wild_directory()- Project validation- Print functions and utilities
test_project_detection.bats
Tests project detection and script execution:
- Script execution from various directory levels
- Environment variable setup from different paths
- Proper failure outside project directories
test_config_functions.bats
Tests configuration and secret access:
wild-configcommandwild-secretcommand- Configuration access from subdirectories
- Fixture data usage
Running Tests
# Initialize git submodules (first time only)
git submodule update --init --recursive
# Run all Bats tests
./run_bats_tests.sh
# Run individual test files
./bats/bin/bats test_common_functions.bats
./bats/bin/bats test_project_detection.bats
./bats/bin/bats test_config_functions.bats
# Test from subdirectory (should work)
cd deep/nested/path
../../../bin/wild-cluster-node-up --help
Fixtures
The fixtures/ directory contains:
sample-config.yaml- Complete test configurationsample-secrets.yaml- Test secrets file
Adding New Tests
-
Create
test_<feature>.batsfollowing the Bats pattern:#!/usr/bin/env bats load 'test_helper' setup() { setup_test_project "feature-test" } teardown() { teardown_test_project "feature-test" } @test "feature description" { # Your test here using Bats assertions run some_command assert_success assert_output "expected output" } -
Add test data to
fixtures/if needed -
The Bats runner will automatically discover and run new tests
Common Test Functions
From test_helper.bash:
setup_test_project "name"- Creates test project intmp/teardown_test_project "name"- Removes test projectcreate_test_project "name" [with-config]- Creates additional test projectsremove_test_project "name"- Removes additional test projects
Bats Assertions
Available through bats-assert:
assert_success/assert_failure- Check command exit statusassert_output "text"- Check exact outputassert_output --partial "text"- Check output contains textassert_equal "$actual" "$expected"- Check equalityassert [ condition ]- General assertions