Browse Source

Merge pull request #74 from maziggy/fix/ci-all-tests

Run all backend tests in CI (unit + integration)
MartinNYHC 4 months ago
parent
commit
f14ca7bb12
1 changed files with 66 additions and 14 deletions
  1. 66 14
      .github/workflows/ci.yml

+ 66 - 14
.github/workflows/ci.yml

@@ -66,10 +66,10 @@ jobs:
           pip install -r requirements.txt
           pip install -r requirements.txt
           pip install pytest pytest-asyncio pytest-cov
           pip install pytest pytest-asyncio pytest-cov
 
 
-      - name: Run unit tests
+      - name: Run tests
         run: |
         run: |
           cd backend
           cd backend
-          python -m pytest tests/unit/ -v --tb=short -m "not slow"
+          python -m pytest tests/ -v --tb=short
 
 
   # ============================================================================
   # ============================================================================
   # Frontend Checks
   # Frontend Checks
@@ -162,24 +162,76 @@ jobs:
         run: npm run build
         run: npm run build
 
 
   # ============================================================================
   # ============================================================================
-  # Docker Build (optional, for release confidence)
+  # Docker Tests (matches test_docker.sh)
   # ============================================================================
   # ============================================================================
 
 
-  docker-build:
+  docker-test:
     name: Docker Build
     name: Docker Build
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
     needs: [backend-tests, frontend-build]
     needs: [backend-tests, frontend-build]
     steps:
     steps:
       - uses: actions/checkout@v4
       - uses: actions/checkout@v4
 
 
-      - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v3
+      # Test 1: Docker Build
+      - name: Build production image
+        run: docker build -t bambuddy:test .
 
 
-      - name: Build Docker image
-        uses: docker/build-push-action@v6
-        with:
-          context: .
-          push: false
-          tags: bambuddy:test
-          cache-from: type=gha
-          cache-to: type=gha,mode=max
+      - name: Verify backend imports
+        run: docker run --rm bambuddy:test python -c "import backend.app.main; print('Backend imports OK')"
+
+      - name: Verify static files exist
+        run: docker run --rm bambuddy:test test -d /app/static
+
+      # Test 2: Backend Unit Tests in Docker
+      - name: Build backend test image
+        run: docker compose -f docker-compose.test.yml build backend-test
+
+      - name: Run backend tests in Docker
+        run: docker compose -f docker-compose.test.yml run --rm backend-test
+
+      # Test 3: Frontend Unit Tests in Docker
+      - name: Build frontend test image
+        run: docker compose -f docker-compose.test.yml build frontend-test
+
+      - name: Run frontend tests in Docker
+        run: docker compose -f docker-compose.test.yml run --rm frontend-test
+
+      # Test 4: Integration Tests
+      - name: Build integration container
+        run: docker compose -f docker-compose.test.yml build integration
+
+      - name: Start integration container
+        run: |
+          docker compose -f docker-compose.test.yml up -d integration
+          echo "Waiting for container to be healthy..."
+          for i in {1..30}; do
+            if docker compose -f docker-compose.test.yml ps integration | grep -q "healthy"; then
+              echo "Container is healthy"
+              break
+            fi
+            sleep 2
+          done
+
+      - name: Test health endpoint
+        run: |
+          HEALTH=$(docker compose -f docker-compose.test.yml exec -T integration curl -s http://localhost:8000/health)
+          echo "$HEALTH"
+          echo "$HEALTH" | grep -q "healthy"
+
+      - name: Test API endpoint
+        run: |
+          docker compose -f docker-compose.test.yml exec -T integration curl -s http://localhost:8000/api/v1/settings
+
+      - name: Test static files served
+        run: |
+          STATUS=$(docker compose -f docker-compose.test.yml exec -T integration curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/)
+          echo "Static files HTTP status: $STATUS"
+          [ "$STATUS" = "200" ]
+
+      - name: Show logs on failure
+        if: failure()
+        run: docker compose -f docker-compose.test.yml logs
+
+      - name: Cleanup
+        if: always()
+        run: docker compose -f docker-compose.test.yml down -v --remove-orphans