Skip to content

Tests

Tests #42

Workflow file for this run

name: Tests
on:
workflow_run:
workflows: ["CodeQL"]
branches: [main]
types:
- completed
pull_request:
branches:
- 'main'
- 'release-*'
tags:
- 'v*.*.*'
permissions:
contents: read
issues: read
checks: write
pull-requests: write
jobs:
test-docker-build:
runs-on: ubuntu-latest
strategy:
max-parallel: 6
matrix:
wazuh_agent_version: ['4.3.10-1','4.4.5-1', '4.5.4-1', '4.6.0-1', '4.7.1-1', '4.7.2-1']
include:
- dockerfile: ./Dockerfile
image: wazuh-agent-minideb
wazuh_cluster_version: '4.7.0'
- dockerfile: ./images/Dockerfile.amazonlinux
image: wazuh-agent-amazonlinux
wazuh_cluster_version: '4.7.0'
- dockerfile: ./images/Dockerfile.ubuntu
image: wazuh-agent-ubuntu
wazuh_cluster_version: '4.7.0'
steps:
- uses: actions/checkout@v3
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker images.
uses: ScribeMD/[email protected]
with:
key: docker-${{ matrix.wazuh_agent_version }}
- name: Build and Save Wazuh Agent base image
run: |
mkdir -p ${{ github.workspace }}/docker-images/
docker build -t ${{ matrix.image }}:${{ matrix.wazuh_agent_version }} -f ${{ matrix.dockerfile }} --build-arg AGENT_VERSION=${{ matrix.wazuh_agent_version }} .
docker pull wazuh/wazuh-manager:${{ matrix.wazuh_cluster_version }}
docker pull wazuh/wazuh-indexer:${{ matrix.wazuh_cluster_version }}
docker pull wazuh/wazuh-dashboard:${{ matrix.wazuh_cluster_version }}
pyunit-tests:
runs-on: ubuntu-latest
needs: ["test-docker-build"]
strategy:
max-parallel: 6
matrix:
wazuh_agent_version: ['4.3.10-1','4.4.5-1', '4.5.4-1', '4.6.0-1', '4.7.1-1', '4.7.2-1']
include:
- image: wazuh-agent-minideb
- image: wazuh-agent-amazonlinux
- image: wazuh-agent-ubuntu
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Cache Docker images.
uses: ScribeMD/[email protected]
with:
key: docker-${{ matrix.wazuh_agent_version }}
- name: Test with pytest
run: |
pytest -n auto -v --capture=sys -x --tb=long --junitxml=/tmp/test-results/wazuh-unittests-${{ matrix.wazuh_agent_version }}.xml
env:
AGENT_VERSION: "${{ matrix.wazuh_agent_version }}"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: wazuh-unittests
path: /tmp/test-results/wazuh-unittests-${{ matrix.wazuh_agent_version }}.xml
integrations-tests:
needs: ["pyunit-tests"]
runs-on: ubuntu-latest
strategy:
matrix:
wazuh_agent_version: ['4.3.10-1','4.4.5-1', '4.5.4-1','4.6.0-1','4.7.1-1','4.7.2-1']
wazuh_cluster_version: ['4.7.0']
include:
- image: wazuh-agent-minideb
- image: wazuh-agent-amazonlinux
- image: wazuh-agent-ubuntu
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: "3.9"
cache: 'pip'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
mkdir -p ${{ github.workspace }}/docker-images/
- name: Cache Docker images.
uses: ScribeMD/[email protected]
with:
key: docker-${{ matrix.wazuh_agent_version }}
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: wazuh-unittests
path: ${{ github.workspace }}/test-results/
- name: Create single node certificates
run: docker-compose -f tests/single-node/generate-indexer-certs.yml run --rm generator
- name: Start single node stack
run: docker-compose -f docker-compose.yml up -d --build
env:
AGENT_VERSION: "${{ matrix.wazuh_agent_version }}"
WAZUH_CLUSTER_VERSION: "${{ matrix.wazuh_cluster_version }}"
- name: Check Wazuh indexer start
run: |
sleep 60
status_green="`curl -XGET "https://0.0.0.0:9200/_cluster/health" -u admin:SecretPassword -k -s | grep green | wc -l`"
if [[ $status_green -eq 1 ]]; then
curl -XGET "https://0.0.0.0:9200/_cluster/health" -u admin:SecretPassword -k -s
else
curl -XGET "https://0.0.0.0:9200/_cluster/health" -u admin:SecretPassword -k -s
exit 1
fi
status_index="`curl -XGET "https://0.0.0.0:9200/_cat/indices" -u admin:SecretPassword -k -s | wc -l`"
status_index_green="`curl -XGET "https://0.0.0.0:9200/_cat/indices" -u admin:SecretPassword -k -s | grep "green" | wc -l`"
if [[ $status_index_green -eq $status_index ]]; then
curl -XGET "https://0.0.0.0:9200/_cat/indices" -u admin:SecretPassword -k -s
else
curl -XGET "https://0.0.0.0:9200/_cat/indices" -u admin:SecretPassword -k -s
exit 1
fi
- name: Integration test for Wazuh agent
run: pytest -v --capture=sys -x --tb=long .github/workflows/test_docker_compose.py --disable-warnings --junitxml=/tmp/test-results/wazuh-docker-compose-${{ matrix.wazuh_agent_version }}.xml
- name: Copy Test Results
if: always()
run: |
cp -Lpr /tmp/test-results/wazuh-docker-compose-${{ matrix.wazuh_agent_version }}.xml ${{ github.workspace }}/test-results/wazuh-docker-compose-${{ matrix.wazuh_agent_version }}.xml
shell: bash
- name: Check results
run: |
ls -R ${{ github.workspace }}/test-results/
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
test-results/**/*.xml
- name: Stop containers and destroy
if: always()
run: docker-compose -f docker-compose.yml down