Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Feb 5, 2025
1 parent 703e00a commit 8481fda
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
52 changes: 26 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,37 @@ jobs:
- run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
- run: rm -Rf /tmp/docker-image/
- run: echo -e "${{ env.DOCKER_IMAGE }}:${{ env.PLATFORM_PAIR }}" | xargs -I % sh -c 'docker run -v /tmp/trivy:/var/lib/trivy -v /var/run/docker.sock:/var/run/docker.sock -t aquasec/trivy:latest --cache-dir /var/lib/trivy image --exit-code 1 --no-progress --format table % || true'
# tests:
# name: Test ${{ matrix.platform }}
# needs:
# - supported-platform-matrix
# - scan-vulnerability
# strategy:
# fail-fast: false
# matrix:
# platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }}
# runs-on: ubuntu-latest
# steps:
# - name: Prepare
# run: |
# platform=${{ matrix.platform }}
# echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# - uses: actions/checkout@v4
# - uses: actions/download-artifact@v4
# with:
# name: docker-image-${{ env.PLATFORM_PAIR }}
# path: /tmp/docker-image
# - run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
# - run: docker image ls -a
# - run: ./tests.sh "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}"
tests:
name: Test ${{ matrix.platform }}
needs:
- supported-platform-matrix
- scan-vulnerability
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }}
runs-on: ubuntu-latest
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: docker-image-${{ env.PLATFORM_PAIR }}
path: /tmp/docker-image
- run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
- run: docker image ls -a
- run: docker run --rm -v "$(pwd)/tests:/tests" -v "/var/run/docker.sock:/var/run/docker.sock:ro" -t "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}"
push-image:
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/main'
name: Push
needs:
- supported-platform-matrix
# - tests
- tests
runs-on: ubuntu-latest
services:
registry:
Expand Down
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ LABEL org.label-schema.title="Testinfra Docker container" \
org.opencontainers.image.vendor="WyriHaximus.net" \
org.opencontainers.image.authors="Cees-Jan Kiewiet <[email protected]>"

WORKDIR /project

# hadolint ignore=DL3018
RUN apk add --no-cache docker python3 py-pip
# hadolint ignore=DL3013
RUN pip install --no-cache-dir docker --break-system-packages && \
# hadolint ignore=DL3018,DL3013
RUN set -e && \
apk add --no-cache docker python3 py-pip && \
pip3 install --no-cache-dir --upgrade pip --break-system-packages && \
pip install --no-cache-dir docker --break-system-packages && \
pip install --no-cache-dir pytest-testinfra --break-system-packages

WORKDIR /tests

ENTRYPOINT ["py.test", "-p", "no:cacheprovider"]
13 changes: 13 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

def test_docker(host):
output = host.run('docker -v')
assert output.rc == 0
assert u'Docker version ' in output.stdout
assert output.stderr == ''

def test_pip(host):
assert host.exists("pip")

def test_pytest(host):
assert host.exists("py.test")

0 comments on commit 8481fda

Please sign in to comment.