#!/bin/bash
# Test cluster_import.go via the CLI
# Exercises ImportCluster, GetLocationData, EnsureClusterPath, batchProcessFiles, insertClusterFiles
# Uses fresh copy of production DB in /tmp (auto-cleaned)
# Create fresh test database
DB_PATH=
SKRAAK="/skraak"
# Create test entities in DB
DATASET_RESULT=
DATASET_ID=
if [; then
|
fi
LOCATION_RESULT=
LOCATION_ID=
if [; then
fi
CLUSTER_RESULT=
CLUSTER_ID=
if [; then
fi
# Helper: extract JSON object from mixed stdout/stderr output
# Create test WAV files
WAV_DIR="/tmp/skraak_cluster_test_"
# Create test WAV files - each with unique content to avoid hash collisions
# Make second file unique by appending a byte (still valid enough for header parsing)
# -------------------------------------------------------
# Test 1: Happy path - import folder
# -------------------------------------------------------
RESULT=
JSON=
IMPORTED=
FAILED=
if [ && [; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 2: DB state - file records exist
# -------------------------------------------------------
FILE_COUNT=
if [; then
|| ; ||
else
|| ; ||
fi
# -------------------------------------------------------
# Test 3: DB state - file_dataset junction records
# -------------------------------------------------------
FD_COUNT=
if [; then
|| ; ||
else
|| ; ||
fi
# -------------------------------------------------------
# Test 4: DB state - astronomical data computed
# -------------------------------------------------------
ASTRO_RESULT=
SOLAR_NIGHT=
MOON_PHASE=
if [ && [; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 5: DB state - duration correct
# -------------------------------------------------------
DURATION=
# Duration should be approximately 1.0 (within 0.1 tolerance)
if [ && [; then
# Use awk for float comparison
APPROX_OK=
if [; then
|| ; ||
else
|| ; ||
fi
else
|| ; ||
fi
# -------------------------------------------------------
# Test 6: EnsureClusterPath - cluster path set after import
# -------------------------------------------------------
CLUSTER_PATH=
if [ && [; then
|| ; ||
else
|| ; ||
fi
# -------------------------------------------------------
# Test 7: Duplicate detection - re-import should skip
# -------------------------------------------------------
# Need a new cluster to re-import into (hash dedup is global)
CLUSTER2_RESULT=
CLUSTER2_ID=
RESULT2=
JSON2=
SKIPPED=
IMPORTED2=
if [ && [; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 8: Empty folder - no WAV files
# -------------------------------------------------------
EMPTY_DIR="/tmp/skraak_empty_test_"
CLUSTER3_RESULT=
CLUSTER3_ID=
RESULT3=
JSON3=
TOTAL_FILES=
if [; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 9: Invalid location ID
# -------------------------------------------------------
CLUSTER4_RESULT=
CLUSTER4_ID=
RESULT4=
if | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 10: Non-existent folder
# -------------------------------------------------------
RESULT5=
if | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 11: Recursive vs non-recursive
# -------------------------------------------------------
CLUSTER5_RESULT=
CLUSTER5_ID=
# The nested file has same hash as the others (identical silence), so it'll be skipped
# But total_files should show 3 (2 top-level + 1 nested)
RESULT6=
JSON6=
TOTAL=
if [; then
|| ; ||
else
|
|| ; ||
fi
# Cleanup