Skip to content

Commit 7bebabc

Browse files
author
Peng Ren
committed
enhance CI
1 parent 9173e8b commit 7bebabc

File tree

6 files changed

+15
-223
lines changed

6 files changed

+15
-223
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ jobs:
1212
strategy:
1313
matrix:
1414
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
15+
mongodb-version: ['7.0', '8.0']
1516

1617
services:
1718
mongodb:
18-
image: mongo:8.0
19+
image: mongo:${{ matrix.mongodb-version }}
1920
env:
2021
MONGO_INITDB_ROOT_USERNAME: admin
2122
MONGO_INITDB_ROOT_PASSWORD: secret
@@ -39,9 +40,9 @@ jobs:
3940
uses: actions/cache@v3
4041
with:
4142
path: ~/.cache/pip
42-
key: ${{ runner.os }}-py${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements-test.txt') }}
43+
key: ${{ runner.os }}-py${{ matrix.python-version }}-mongo${{ matrix.mongodb-version }}-pip-${{ hashFiles('**/requirements-test.txt') }}
4344
restore-keys: |
44-
${{ runner.os }}-py${{ matrix.python-version }}-pip-
45+
${{ runner.os }}-py${{ matrix.python-version }}-mongo${{ matrix.mongodb-version }}-pip-
4546
4647
- name: Install MongoDB shell
4748
run: |
@@ -74,7 +75,7 @@ jobs:
7475
- name: Set up test database
7576
run: |
7677
echo "Setting up test database..."
77-
python tests/mongo_test_helper.py setup || true
78+
python tests/run_test_server.py setup || true
7879
7980
- name: Run tests
8081
run: |

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

tests/docker-compose.test.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def check_docker():
3030
return False, f"Docker check failed: {e}"
3131

3232

33-
def start_mongodb_docker():
33+
def start_mongodb_docker(version="8.0"):
3434
"""Start MongoDB in Docker container"""
3535
print("Checking Docker availability...")
3636
docker_ok, docker_msg = check_docker()
@@ -63,7 +63,7 @@ def start_mongodb_docker():
6363
)
6464

6565
# Start new container with authentication
66-
print(" Starting new MongoDB 8.0 container with auth...")
66+
print(f" Starting new MongoDB {version} container with auth...")
6767
result = subprocess.run(
6868
[
6969
"docker",
@@ -79,7 +79,7 @@ def start_mongodb_docker():
7979
"MONGO_INITDB_ROOT_PASSWORD=secret",
8080
"-e",
8181
"MONGO_INITDB_DATABASE=test_db",
82-
"mongo:8.0",
82+
f"mongo:{version}",
8383
],
8484
capture_output=True,
8585
text=True,
@@ -220,19 +220,21 @@ def suggest_alternatives():
220220

221221
def main():
222222
"""Main function"""
223-
if len(sys.argv) != 2:
223+
if len(sys.argv) < 2 or len(sys.argv) > 3:
224224
print(
225-
"Usage: python mongo_test_helper.py [start|stop|setup|status|alternatives|test]"
225+
"Usage: python run_test_server.py [start|stop|setup|status|alternatives|test] [version]"
226226
)
227+
print("Version examples: 7.0, 8.0 (default: 8.0)")
227228
sys.exit(1)
228229

229230
command = sys.argv[1]
231+
version = sys.argv[2] if len(sys.argv) == 3 else "8.0"
230232

231233
if command == "start":
232-
if start_mongodb_docker():
234+
if start_mongodb_docker(version):
233235
if wait_for_mongodb():
234236
setup_test_data()
235-
print("\n✅ MongoDB test instance is ready!")
237+
print(f"\n✅ MongoDB {version} test instance is ready!")
236238
print("Connection: mongodb://localhost:27017/test_db")
237239
else:
238240
print("❌ MongoDB failed to start properly")

tests/setup_mongo.bat

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/setup_mongo.ps1

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)