name: Linux
on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [22.x, 24.x, 26.x]
    steps:
    - name: Harden Runner
      uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
      with:
        egress-policy: audit
    - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install throttle
      run: npm ci
    - name: Install dependencies
      run: sudo apt-get install -y net-tools
    - name: Verify lint
      run: npm run lint
    - name: Show interfaces
      run: sudo ip route show
    - name: Get default interface
      run: sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'
    - name: Test cable
      run: LOG_THROTTLE=true bin/index.js cable && bin/index.js stop
    - name: Test configuration
      run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 && bin/index.js stop
    - name: Test localhost
      run: LOG_THROTTLE=true bin/index.js --rtt 200 --localhost && bin/index.js stop --localhost
    - name: Test config file
      run: LOG_THROTTLE=true bin/index.js --config test/config.json && bin/index.js stop
    - name: Test packet loss
      run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 --packetLoss 10 && bin/index.js stop
    - name: Test packet loss and profile
      run: LOG_THROTTLE=true bin/index.js 3g --packetLoss 10 && bin/index.js stop
