Skip to content
Merged
Show file tree
Hide file tree
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
280 changes: 280 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Test Apollo Supergraph

on:

Check warning on line 4 in .github/workflows/test.yaml

View workflow job for this annotation

GitHub Actions / Test Kubernetes YAML Format

4:1 [truthy] truthy value should be one of [false, true]
pull_request:
branches:
- main
Expand Down Expand Up @@ -134,9 +134,289 @@
./kill-minikube.sh --help || exit 1
./setup-minikube.sh --help || exit 1
./setup-env.sh --help || exit 1
./test-router.sh --help || exit 1

echo "✅ All script help options working"

- name: Test new test utilities
run: |
# Test that test utilities can be sourced without errors
echo "Testing test utilities..."

# Source test utilities and test basic functions
source scripts/test-utils.sh

# Test that functions are available
if ! type test_router_health > /dev/null 2>&1; then
echo "❌ test_router_health function not found"
exit 1
fi

if ! type test_search_products > /dev/null 2>&1; then
echo "❌ test_search_products function not found"
exit 1
fi

if ! type test_router_comprehensive > /dev/null 2>&1; then
echo "❌ test_router_comprehensive function not found"
exit 1
fi

echo "✅ Test utilities functions available"

# Test that test utilities can be run directly
echo "Testing test utilities execution..."

# Test that the script can be run with --help (should show usage)
if ! bash scripts/test-utils.sh --help 2>&1 | \
grep -q "Available tests"; then
echo "❌ test-utils.sh --help not working correctly"
exit 1
fi

echo "✅ Test utilities execution working"

- name: Test script organization
run: |
echo "🔍 Dynamically discovering scripts..."

# Discover user-facing scripts in root directory
echo "📁 Checking user-facing scripts in root directory..."
user_scripts=($(find . -maxdepth 1 -name "*.sh" -type f \
-exec basename {} \; | grep -v "^\.$"))

if [ ${#user_scripts[@]} -eq 0 ]; then
echo "❌ No user-facing scripts found in root directory"
exit 1
fi

echo "✅ Found ${#user_scripts[@]} user-facing scripts:"
for script in "${user_scripts[@]}"; do
echo " - $script"
done

# Discover internal scripts in scripts directory
echo "📁 Checking internal scripts in scripts directory..."
if [ ! -d "scripts" ]; then
echo "❌ scripts directory not found"
exit 1
fi

internal_scripts=($(find scripts -name "*.sh" -type f \
-exec basename {} \;))

if [ ${#internal_scripts[@]} -eq 0 ]; then
echo "❌ No internal scripts found in scripts directory"
exit 1
fi

echo "✅ Found ${#internal_scripts[@]} internal scripts:"
for script in "${internal_scripts[@]}"; do
echo " - scripts/$script"
done

echo "✅ Script organization is correct"

# Test that scripts are using test utilities (no duplication)
echo "Testing for script duplication..."

# Check all scripts for hardcoded curl commands that should use test
# utilities
echo "🔍 Checking for hardcoded curl commands in scripts..."

# Check user-facing scripts
for script in "${user_scripts[@]}"; do
if grep -q "curl.*localhost:4000" "$script"; then
echo "❌ $script contains hardcoded curl commands for router \
testing"
echo " Should use test utilities instead"
exit 1
fi
done

# Check internal scripts (but allow some curl usage in test-utils.sh
# itself)
for script in "${internal_scripts[@]}"; do
if [ "$script" != "test-utils.sh" ] && \
grep -q "curl.*localhost:4000.*health" "scripts/$script"; then
echo "❌ scripts/$script contains hardcoded curl commands for \
health checks"
echo " Should use test utilities instead"
exit 1
fi
done

echo "✅ No duplication found - scripts using test utilities \
correctly"

# Test that test utilities contain expected functions
echo "Testing test utilities content..."

# Check that test-utils.sh exists
if [ ! -f "scripts/test-utils.sh" ]; then
echo "❌ test-utils.sh not found in scripts directory"
exit 1
fi

# Discover test functions dynamically
echo "🔍 Discovering test functions in test-utils.sh..."
test_functions=($(grep -E "^test_[a-zA-Z_]+\(\)" \
scripts/test-utils.sh | sed 's/() {.*//' | sort))

if [ ${#test_functions[@]} -eq 0 ]; then
echo "❌ No test functions found in test-utils.sh"
exit 1
fi

echo "✅ Found ${#test_functions[@]} test functions:"
for func in "${test_functions[@]}"; do
echo " - $func"
done

# Check for essential test functions
essential_functions=("test_router_health" "test_search_products")
for func in "${essential_functions[@]}"; do
if [[ ! " ${test_functions[@]} " =~ " ${func} " ]]; then
echo "❌ Essential test function not found: $func"
exit 1
fi
done

echo "✅ Test utilities contain essential functions"

# Test that test-router.sh works correctly
echo "Testing test-router.sh functionality..."

# Check that test-router.sh exists
if [ ! -f "test-router.sh" ]; then
echo "❌ test-router.sh not found in root directory"
exit 1
fi

# Test that it can show help
if ! ./test-router.sh --help 2>&1 | grep -q "Test Names:"; then
echo "❌ test-router.sh --help not working correctly"
exit 1
fi

# Discover available tests dynamically
echo "🔍 Discovering available tests in test-router.sh..."
available_tests=($(./test-router.sh --help 2>&1 | \
grep -A 20 "Test Names:" | grep -E "^ [a-zA-Z-]+" | \
sed 's/^ //' | sed 's/ .*//' | tr '\n' ' '))

if [ ${#available_tests[@]} -eq 0 ]; then
echo "❌ No tests found in test-router.sh help output"
exit 1
fi

echo "✅ Found ${#available_tests[@]} available tests:"
for test in "${available_tests[@]}"; do
echo " - $test"
done

# Check for essential tests
essential_tests=("health" "products" "status" "all")
for test in "${essential_tests[@]}"; do
if [[ ! " ${available_tests[@]} " =~ " ${test} " ]]; then
echo "❌ Essential test not found: $test"
exit 1
fi
done

echo "✅ test-router.sh functionality working correctly"

# Test that build validation script exists and has help
echo "Testing build validation script..."

# Check if build-validate.sh exists
if [ ! -f "scripts/build-validate.sh" ]; then
echo "❌ build-validate.sh not found in scripts directory"
exit 1
fi

# Test that it has help functionality
if ! ./scripts/build-validate.sh --help 2>&1 | grep -q "Usage:"; then
echo "❌ build-validate.sh --help not working correctly"
exit 1
fi

echo "✅ build-validate.sh exists and has help functionality"

# Test all scripts that have --help functionality
echo "Testing script help functionality..."
echo "🔍 Checking which scripts support --help..."

help_scripts=()
for script in "${user_scripts[@]}"; do
if ./"$script" --help 2>&1 | grep -q "Usage:\|Options:"; then
help_scripts+=("$script")
fi
done

for script in "${internal_scripts[@]}"; do
if ./"scripts/$script" --help 2>&1 | \
grep -q "Usage:\|Options:"; then
help_scripts+=("scripts/$script")
fi
done

if [ ${#help_scripts[@]} -gt 0 ]; then
echo "✅ Found ${#help_scripts[@]} scripts with help \
functionality:"
for script in "${help_scripts[@]}"; do
echo " - $script"
done
else
echo "⚠️ No scripts found with help functionality"
fi

# Test that documentation structure is correct
echo "Testing documentation structure..."

# Check that README.md exists and points to SETUP.md
if ! grep -q "SETUP.md" README.md; then
echo "❌ README.md missing reference to SETUP.md"
exit 1
fi

# Check that SETUP.md exists and contains commands
if [ ! -f "SETUP.md" ]; then
echo "❌ SETUP.md not found"
exit 1
fi

# Check that ARCHITECTURE.md exists
if [ ! -f "ARCHITECTURE.md" ]; then
echo "❌ ARCHITECTURE.md not found"
exit 1
fi

# Check that README-K8S.md is deleted
if [ -f "README-K8S.md" ]; then
echo "❌ README-K8S.md still exists (should be deleted)"
exit 1
fi

echo "✅ Documentation structure is correct"

# Test that cleanup-k8s.sh provides helpful output
echo "Testing cleanup-k8s.sh output..."

# Test that it mentions minikube is still running
if ! ./cleanup-k8s.sh 2>&1 | grep -q "Minikube is still running"; then
echo "❌ cleanup-k8s.sh missing minikube warning"
exit 1
fi

# Test that it mentions kill-minikube.sh
if ! ./cleanup-k8s.sh 2>&1 | grep -q "kill-minikube.sh"; then
echo "❌ cleanup-k8s.sh missing kill-minikube.sh reference"
exit 1
fi

echo "✅ cleanup-k8s.sh provides helpful output"

test-k8s-yaml:
name: Test Kubernetes YAML Format
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions AI_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fi
3. **Transform URLs during deployment** (sed replacement to Kubernetes service URLs)
4. **Never commit Kubernetes URLs** to the supergraph.graphql file

### Example of Correct URL Transformation in deploy.sh
### Example of Correct URL Transformation in run-k8s.sh

```bash
# Generate supergraph with localhost URLs first
Expand Down Expand Up @@ -138,7 +138,7 @@ sed 's|http://localhost:4001|http://subgraphs-service.apollo-supergraph.svc.clus
- Faster startup, easier debugging
- No container overhead

2. **Kubernetes Deployment** (`deploy.sh`):
2. **Kubernetes Deployment** (`run-k8s.sh`):
- Runs WITH minikube Kubernetes
- Everything containerized
- Production-like environment
Expand All @@ -153,7 +153,7 @@ sed 's|http://localhost:4001|http://subgraphs-service.apollo-supergraph.svc.clus
**Each script has a specific purpose - don't confuse them:**

- `run-local.sh` - Local development WITHOUT Kubernetes
- `deploy.sh` - Kubernetes deployment WITH minikube
- `run-k8s.sh` - Kubernetes deployment WITH minikube
- `setup-minikube.sh` - Setup minikube cluster
- `kill-minikube.sh` - Stop and delete minikube cluster
- `cleanup-k8s.sh` - Clean up Kubernetes resources
Expand All @@ -178,7 +178,7 @@ sed 's|http://localhost:4001|http://subgraphs-service.apollo-supergraph.svc.clus
### Recommended Development Process

1. **Start with local development** (`run-local.sh`) for faster iteration
2. **Use Kubernetes deployment** (`deploy.sh`) for testing production-like environments
2. **Use Kubernetes deployment** (`run-k8s.sh`) for testing production-like environments
3. **Keep configurations in router folder** as source of truth
4. **Generate supergraph** with `./compose.sh` before deployments
5. **Transform URLs** during deployment (localhost → Kubernetes service URLs)
Expand Down
Loading