|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + paths: |
| 7 | + - 'crates/**' |
| 8 | + - 'Cargo.toml' |
| 9 | + - 'Cargo.lock' |
| 10 | + - '.github/workflows/test.yml' |
| 11 | + pull_request: |
| 12 | + branches: [main] |
| 13 | + paths: |
| 14 | + - 'crates/**' |
| 15 | + - 'Cargo.toml' |
| 16 | + - 'Cargo.lock' |
| 17 | + - '.github/workflows/test.yml' |
| 18 | + |
| 19 | +env: |
| 20 | + CARGO_TERM_COLOR: always |
| 21 | + RUST_BACKTRACE: 1 |
| 22 | + |
| 23 | +jobs: |
| 24 | + # Fast checks - runs first to fail fast on simple issues |
| 25 | + check: |
| 26 | + name: Check & Lint |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Install Rust toolchain |
| 32 | + uses: dtolnay/rust-toolchain@stable |
| 33 | + with: |
| 34 | + components: clippy, rustfmt |
| 35 | + |
| 36 | + - name: Cache cargo registry |
| 37 | + uses: actions/cache@v4 |
| 38 | + with: |
| 39 | + path: | |
| 40 | + ~/.cargo/registry |
| 41 | + ~/.cargo/git |
| 42 | + target |
| 43 | + key: ${{ runner.os }}-cargo-check-${{ hashFiles('**/Cargo.lock') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-cargo-check- |
| 46 | +
|
| 47 | + - name: Check formatting |
| 48 | + run: cargo fmt --all -- --check |
| 49 | + |
| 50 | + - name: Run clippy |
| 51 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 52 | + |
| 53 | + - name: Check compilation |
| 54 | + run: cargo check --all-targets |
| 55 | + |
| 56 | + # Unit tests - fast, no external dependencies |
| 57 | + unit-tests: |
| 58 | + name: Unit Tests |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: check |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v4 |
| 63 | + |
| 64 | + - name: Install Rust toolchain |
| 65 | + uses: dtolnay/rust-toolchain@stable |
| 66 | + |
| 67 | + - name: Cache cargo registry |
| 68 | + uses: actions/cache@v4 |
| 69 | + with: |
| 70 | + path: | |
| 71 | + ~/.cargo/registry |
| 72 | + ~/.cargo/git |
| 73 | + target |
| 74 | + key: ${{ runner.os }}-cargo-unit-${{ hashFiles('**/Cargo.lock') }} |
| 75 | + restore-keys: | |
| 76 | + ${{ runner.os }}-cargo-unit- |
| 77 | +
|
| 78 | + - name: Run unit tests (lib) |
| 79 | + run: cargo test --lib --all-features |
| 80 | + env: |
| 81 | + RUST_LOG: debug |
| 82 | + |
| 83 | + - name: Run unit test suite |
| 84 | + run: cargo test --test unit --all-features |
| 85 | + env: |
| 86 | + RUST_LOG: debug |
| 87 | + |
| 88 | + # Integration tests - require Docker |
| 89 | + integration-tests: |
| 90 | + name: Integration Tests |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: unit-tests |
| 93 | + services: |
| 94 | + # Docker-in-Docker for testcontainers |
| 95 | + dind: |
| 96 | + image: docker:dind |
| 97 | + options: --privileged |
| 98 | + |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + |
| 102 | + - name: Install Rust toolchain |
| 103 | + uses: dtolnay/rust-toolchain@stable |
| 104 | + |
| 105 | + - name: Cache cargo registry |
| 106 | + uses: actions/cache@v4 |
| 107 | + with: |
| 108 | + path: | |
| 109 | + ~/.cargo/registry |
| 110 | + ~/.cargo/git |
| 111 | + target |
| 112 | + key: ${{ runner.os }}-cargo-integration-${{ hashFiles('**/Cargo.lock') }} |
| 113 | + restore-keys: | |
| 114 | + ${{ runner.os }}-cargo-integration- |
| 115 | +
|
| 116 | + - name: Run integration tests |
| 117 | + run: cargo test --test integration --all-features -- --nocapture |
| 118 | + env: |
| 119 | + DOCKER_HOST: unix:///var/run/docker.sock |
| 120 | + RUST_LOG: debug |
| 121 | + TESTCONTAINERS: "true" |
| 122 | + |
| 123 | + - name: Run integration test suite |
| 124 | + run: cargo test --test integration_tests --all-features -- --nocapture --include-ignored |
| 125 | + env: |
| 126 | + DOCKER_HOST: unix:///var/run/docker.sock |
| 127 | + RUST_LOG: debug |
| 128 | + TESTCONTAINERS: "true" |
| 129 | + timeout-minutes: 15 |
| 130 | + |
| 131 | + # Chaos tests - slower, may require special setup |
| 132 | + chaos-tests: |
| 133 | + name: Chaos Tests |
| 134 | + runs-on: ubuntu-latest |
| 135 | + needs: integration-tests |
| 136 | + # Only run on main branch or when explicitly requested |
| 137 | + if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run-chaos-tests') |
| 138 | + |
| 139 | + steps: |
| 140 | + - uses: actions/checkout@v4 |
| 141 | + |
| 142 | + - name: Install Rust toolchain |
| 143 | + uses: dtolnay/rust-toolchain@stable |
| 144 | + |
| 145 | + - name: Cache cargo registry |
| 146 | + uses: actions/cache@v4 |
| 147 | + with: |
| 148 | + path: | |
| 149 | + ~/.cargo/registry |
| 150 | + ~/.cargo/git |
| 151 | + target |
| 152 | + key: ${{ runner.os }}-cargo-chaos-${{ hashFiles('**/Cargo.lock') }} |
| 153 | + restore-keys: | |
| 154 | + ${{ runner.os }}-cargo-chaos- |
| 155 | +
|
| 156 | + - name: Run chaos tests (non-ignored only) |
| 157 | + run: cargo test --test chaos_tests --all-features -- --nocapture |
| 158 | + env: |
| 159 | + DOCKER_HOST: unix:///var/run/docker.sock |
| 160 | + RUST_LOG: debug |
| 161 | + timeout-minutes: 20 |
| 162 | + |
| 163 | + # Coverage reporting |
| 164 | + coverage: |
| 165 | + name: Code Coverage |
| 166 | + runs-on: ubuntu-latest |
| 167 | + needs: unit-tests |
| 168 | + # Only run on main branch pushes |
| 169 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 170 | + |
| 171 | + steps: |
| 172 | + - uses: actions/checkout@v4 |
| 173 | + |
| 174 | + - name: Install Rust toolchain |
| 175 | + uses: dtolnay/rust-toolchain@stable |
| 176 | + |
| 177 | + - name: Install cargo-tarpaulin |
| 178 | + uses: taiki-e/install-action@cargo-tarpaulin |
| 179 | + |
| 180 | + - name: Cache cargo registry |
| 181 | + uses: actions/cache@v4 |
| 182 | + with: |
| 183 | + path: | |
| 184 | + ~/.cargo/registry |
| 185 | + ~/.cargo/git |
| 186 | + target |
| 187 | + key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }} |
| 188 | + restore-keys: | |
| 189 | + ${{ runner.os }}-cargo-coverage- |
| 190 | +
|
| 191 | + - name: Generate coverage report |
| 192 | + run: | |
| 193 | + cargo tarpaulin \ |
| 194 | + --out Xml \ |
| 195 | + --out Html \ |
| 196 | + --timeout 300 \ |
| 197 | + --ignore-panics \ |
| 198 | + --ignore-tests \ |
| 199 | + --workspace \ |
| 200 | + --exclude-files "*/tests/*" |
| 201 | + continue-on-error: true |
| 202 | + |
| 203 | + - name: Upload coverage to Codecov |
| 204 | + uses: codecov/codecov-action@v4 |
| 205 | + with: |
| 206 | + files: ./cobertura.xml |
| 207 | + fail_ci_if_error: false |
| 208 | + verbose: true |
| 209 | + |
| 210 | + - name: Upload coverage HTML report |
| 211 | + uses: actions/upload-artifact@v4 |
| 212 | + with: |
| 213 | + name: coverage-report |
| 214 | + path: tarpaulin-report.html |
| 215 | + retention-days: 7 |
| 216 | + |
| 217 | + # Security audit |
| 218 | + security-audit: |
| 219 | + name: Security Audit |
| 220 | + runs-on: ubuntu-latest |
| 221 | + steps: |
| 222 | + - uses: actions/checkout@v4 |
| 223 | + |
| 224 | + - name: Install Rust toolchain |
| 225 | + uses: dtolnay/rust-toolchain@stable |
| 226 | + |
| 227 | + - name: Install cargo-audit |
| 228 | + run: cargo install cargo-audit |
| 229 | + |
| 230 | + - name: Run security audit |
| 231 | + run: cargo audit |
| 232 | + continue-on-error: true |
| 233 | + |
| 234 | + # Summary job for branch protection |
| 235 | + tests-complete: |
| 236 | + name: Tests Complete |
| 237 | + runs-on: ubuntu-latest |
| 238 | + needs: [check, unit-tests, integration-tests] |
| 239 | + if: always() |
| 240 | + steps: |
| 241 | + - name: Check all tests passed |
| 242 | + run: | |
| 243 | + if [ "${{ needs.check.result }}" != "success" ] || \ |
| 244 | + [ "${{ needs.unit-tests.result }}" != "success" ] || \ |
| 245 | + [ "${{ needs.integration-tests.result }}" != "success" ]; then |
| 246 | + echo "One or more required jobs failed" |
| 247 | + exit 1 |
| 248 | + fi |
| 249 | + echo "All required tests passed!" |
0 commit comments