Skip to content

Commit

Permalink
Merge pull request #11 from ZEISS/task/fix-test-setup
Browse files Browse the repository at this point in the history
Task/fix test setup
  • Loading branch information
felixZdi authored Jan 9, 2024
2 parents d615d2b + 61e0669 commit d096f0b
Show file tree
Hide file tree
Showing 31 changed files with 1,397 additions and 813 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
20 changes: 11 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ name: main

on:
schedule:
- cron: '0 22 * * 0' # every sunday at 10pm
- cron: "0 22 * * 0" # every sunday at 10pm
push:
branches:
- 'main'
- "main"
tags:
- 'v?[0-9]+.[0-9]+.[0-9]+*'
- "v?[0-9]+.[0-9]+.[0-9]+*"
pull_request:
branches:
- "main"

jobs:
container_build:
Expand All @@ -17,7 +19,7 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set build variables
id: env
run: |
Expand Down Expand Up @@ -48,33 +50,33 @@ jobs:
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[worker.oci]
max-parallelism = 4
- name: Check out Docker Buildx cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
id: docker_build
uses: docker/build-push-action@v5
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Python unittest
on: [push, pull_request]
jobs:
unittest:
runs-on: ubuntu-latest
steps:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
poetry install --all-extras
continue-on-error: true
- name: Test with pytest
run: |
poetry run coverage run
poetry run coverage report
poetry run coverage xml
- uses: 5monkeys/cobertura-action@master
with:
minimum_coverage: 40
fail_below_threshold: true
if: always()
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ src/

# macOS
.DS_Store


# Local testing
acme_dns_azure/config.yaml

# test results
.coverage
junit
test-results
coverage.xml
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,34 @@ curl -sSL https://install.python-poetry.org | python3 -

Configure the virtual environment with full targets support and activate it:

## Install dependencies

```bash
cd acme-dns-azure
poetry install --all-extras
source .venv/bin/activate
```

## Lint

```bash
poetry run black .
```

## Run unit tests

```bash
poetry run coverage run
poetry run coverage report
poetry run coverage xml
```

## Build

```bash
poetry export --without-hashes --format=requirements.txt > targets/function/requirements.txt
```

## Local dev

[Install Azure Function Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v4%2Clinux%2Cpython%2Cportal%2Cbash#install-the-azure-functions-core-tools) for local development:

```bash
Expand All @@ -33,6 +54,8 @@ sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
```

### Local integration testing (WiP)

Azurite:

```bash
Expand All @@ -47,11 +70,14 @@ Make sure the tests pass:
tox -e py
```

## Test
### Manual testing

Prerequisite:

- config.yaml with according configuration within "/acme_dns_azure" (Note: 'sp_client_id' and 'sp_client_secret' are required. 'managed_identity_id' is not allowed)

- Azure keyvault with required secrets

```bash
# unit test
pytest
# specific target
pytest acme_dns_azure/tests/targets/test_foo.py
python client.py
```
2 changes: 1 addition & 1 deletion acme_dns_azure/___init___.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
acme-dns-azure - a ACME client setup based on Certbot for dns-01 challenges via Azure Cloud services.
"""
__author__ = "ZEISS Digital Innovation Partners"
__author__ = "ZEISS Digital Innovation Partners"
Loading

0 comments on commit d096f0b

Please sign in to comment.