chore: add mongosh to check user #34
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI for wishlist service | |
on: | |
push: | |
branches: | |
- NSHM-9-Set-up-environment | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: services/wishlist | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Start MongoDB service | |
run: | | |
docker run -d --name mongo \ | |
-e MONGO_INITDB_ROOT_USERNAME=test_user \ | |
-e MONGO_INITDB_ROOT_PASSWORD=test_password \ | |
-e MONGO_INITDB_DATABASE=test_nshm_wishlist \ | |
-v ${GITHUB_WORKSPACE}/services/wishlist/database/test:/docker-entrypoint-initdb.d \ | |
-p 27017:27017 mongo:latest | |
- name: Wait for MongoDB to be ready | |
run: | | |
for i in {1..10}; do | |
if docker exec mongo mongosh --eval "printjson(db.runCommand({ ping: 1 }))" | grep -q "ok"; then | |
echo "MongoDB is ready!" | |
# Check for users in the test_nshm_wishlist database | |
echo "Listing users in the test_nshm_wishlist database:" | |
docker exec mongo mongosh -u test_user -p test_password --authenticationDatabase admin --eval "use test_nshm_wishlist; db.getUsers()" | |
break | |
fi | |
echo "Waiting for MongoDB to be ready..." | |
sleep 5 | |
done | |
- name: Cache Maven packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Run tests and generate coverage report | |
run: | | |
mvn clean test jacoco:report | |
env: | |
MONGO_HOST: localhost | |
MONGO_PORT: 27017 | |
MONGO_DB: test_nshm_wishlist | |
MONGO_USERNAME: test_user | |
MONGO_PASSWORD: test_password | |
WISHLIST_PORT: 8083 | |
JWT_SECRET_KEY: test_jwt_secret_key | |
- name: Upload Test Coverage Report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: jacoco-report | |
path: target/site/jacoco/jacoco.xml |