-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·87 lines (70 loc) · 2.91 KB
/
test.sh
File metadata and controls
executable file
·87 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Create a temporary test directory
TEST_DIR=$(mktemp -d)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "🧪 Setting up test environment in: $TEST_DIR"
echo "📍 Using script from: $SCRIPT_DIR"
trap "rm -rf $TEST_DIR" EXIT
cd "$TEST_DIR"
# Copy the script to test directory
cp "$SCRIPT_DIR/check_migration_timestamp.sh" .
# Initialize git repo
git init
git config user.email "test@example.com"
git config user.name "Test User"
# Create directory structure
mkdir -p src/models src/migrations
# Create initial files and commit
echo "# Models" > src/models/base.py
echo "# Migration base" > src/migrations/__init__.py
git add .
git commit -m "Initial commit"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo -e "\n${YELLOW}Test 1: No changes (should pass)${NC}"
bash check_migration_timestamp.sh \
--model-dirs=src/models \
--migration-dir=src/migrations \
--exclude=__init__.py && echo -e "${GREEN}✅ PASS${NC}" || echo -e "${RED}❌ FAIL${NC}"
echo -e "\n${YELLOW}Test 2: Model change without migration (should fail)${NC}"
echo "class User: pass" > src/models/user.py
git add src/models/user.py
bash check_migration_timestamp.sh \
--model-dirs=src/models \
--migration-dir=src/migrations \
--exclude=__init__.py && echo -e "${RED}❌ FAIL - Should have failed${NC}" || echo -e "${GREEN}✅ PASS - Correctly failed${NC}"
echo -e "\n${YELLOW}Test 3: Model change with migration (should pass)${NC}"
echo "def upgrade(): pass" > src/migrations/001_add_user.py
git add src/migrations/001_add_user.py
bash check_migration_timestamp.sh \
--model-dirs=src/models \
--migration-dir=src/migrations \
--exclude=__init__.py && echo -e "${GREEN}✅ PASS${NC}" || echo -e "${RED}❌ FAIL${NC}"
echo -e "\n${YELLOW}Test 4: Multiple model dirs with excludes (should pass)${NC}"
git commit -m "Add user model and migration"
mkdir -p src/entities
echo "class Entity: pass" > src/entities/base.py
git add src/entities/base.py
git commit -m "Add entities"
echo "class Post: pass" > src/entities/post.py
git add src/entities/post.py
echo "def upgrade(): pass" > src/migrations/002_add_post.py
git add src/migrations/002_add_post.py
bash check_migration_timestamp.sh \
--model-dirs=src/models,src/entities \
--migration-dir=src/migrations \
--exclude=__init__.py,base.py && echo -e "${GREEN}✅ PASS${NC}" || echo -e "${RED}❌ FAIL${NC}"
echo -e "\n${YELLOW}Test 5: Changes only in excluded files (should pass)${NC}"
git commit -m "Add post model and migration"
echo "# Updated base" >> src/models/base.py
git add src/models/base.py
bash check_migration_timestamp.sh \
--model-dirs=src/models \
--migration-dir=src/migrations \
--exclude=__init__.py,base.py && echo -e "${GREEN}✅ PASS${NC}" || echo -e "${RED}❌ FAIL${NC}"
echo -e "\n${GREEN}✅ All tests completed!${NC}"