Enha(cli): add sort img test case
This commit is contained in:
74
cli-tests/sort-img/check.sh
Executable file
74
cli-tests/sort-img/check.sh
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
LOG_FILE=$(ls -t "$SCRIPT_DIR"/*_run.log 2>/dev/null | head -1)
|
||||||
|
|
||||||
|
PASS=0
|
||||||
|
FAIL=0
|
||||||
|
|
||||||
|
log_pass() {
|
||||||
|
echo "[PASS] $1"
|
||||||
|
PASS=$((PASS + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
log_fail() {
|
||||||
|
echo "[FAIL] $1"
|
||||||
|
FAIL=$((FAIL + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "=== Checking results ==="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check has-animals directory exists
|
||||||
|
if [ -d "/tmp/sort-img/has-animals" ]; then
|
||||||
|
log_pass "has-animals directory exists"
|
||||||
|
else
|
||||||
|
log_fail "has-animals directory missing"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check no-animals directory exists
|
||||||
|
if [ -d "/tmp/sort-img/no-animals" ]; then
|
||||||
|
log_pass "no-animals directory exists"
|
||||||
|
else
|
||||||
|
log_fail "no-animals directory missing"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check has-animals contains at least one image
|
||||||
|
HAS_ANIMALS_FILES=$(ls -1 /tmp/sort-img/has-animals 2>/dev/null | wc -l)
|
||||||
|
if [ "$HAS_ANIMALS_FILES" -gt 0 ]; then
|
||||||
|
log_pass "has-animals contains images ($HAS_ANIMALS_FILES files)"
|
||||||
|
else
|
||||||
|
log_fail "has-animals is empty"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check no-animals contains at least one image
|
||||||
|
NO_ANIMALS_FILES=$(ls -1 /tmp/sort-img/no-animals 2>/dev/null | wc -l)
|
||||||
|
if [ "$NO_ANIMALS_FILES" -gt 0 ]; then
|
||||||
|
log_pass "no-animals contains images ($NO_ANIMALS_FILES files)"
|
||||||
|
else
|
||||||
|
log_fail "no-animals is empty"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check total files sorted correctly (3 original files should be in subdirs)
|
||||||
|
TOTAL_SORTED=$((HAS_ANIMALS_FILES + NO_ANIMALS_FILES))
|
||||||
|
if [ "$TOTAL_SORTED" -eq 3 ]; then
|
||||||
|
log_pass "all 3 files sorted into subdirectories"
|
||||||
|
else
|
||||||
|
log_fail "expected 3 files sorted, got $TOTAL_SORTED"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Summary ==="
|
||||||
|
echo "PASSED: $PASS"
|
||||||
|
echo "FAILED: $FAIL"
|
||||||
|
|
||||||
|
if [ $FAIL -gt 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo "Log file: $LOG_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "All tests passed!"
|
||||||
|
exit 0
|
||||||
25
cli-tests/sort-img/run.sh
Executable file
25
cli-tests/sort-img/run.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
|
LOG_FILE="$SCRIPT_DIR/${TIMESTAMP}_run.log"
|
||||||
|
|
||||||
|
exec > "$LOG_FILE" 2>&1
|
||||||
|
|
||||||
|
echo "=== Running teardown ==="
|
||||||
|
"$SCRIPT_DIR/teardown.sh"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Running setup ==="
|
||||||
|
"$SCRIPT_DIR/setup.sh"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Running task ==="
|
||||||
|
TASK=$(cat "$SCRIPT_DIR/task.txt")
|
||||||
|
cd /home/grail/projects/plays/goplays/gf-lt
|
||||||
|
go run . -cli -msg "$TASK"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Done ==="
|
||||||
|
echo "Log file: $LOG_FILE"
|
||||||
9
cli-tests/sort-img/setup.sh
Executable file
9
cli-tests/sort-img/setup.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
mkdir -p /tmp/sort-img
|
||||||
|
|
||||||
|
cp ../../../assets/ex01.png /tmp/sort-img/file1.png
|
||||||
|
cp ../../../assets/helppage.png /tmp/sort-img/file2.png
|
||||||
|
cp ../../../assets/yt_thumb.jpg /tmp/sort-img/file3.jpg
|
||||||
4
cli-tests/sort-img/teardown.sh
Executable file
4
cli-tests/sort-img/teardown.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
rm -rf /tmp/sort-img
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
LOG_FILE="$SCRIPT_DIR/run.log"
|
LOG_FILE=$(ls -t "$SCRIPT_DIR"/*_run.log 2>/dev/null | head -1)
|
||||||
|
|
||||||
PASS=0
|
PASS=0
|
||||||
FAIL=0
|
FAIL=0
|
||||||
|
|||||||
Reference in New Issue
Block a user