Skip to content

Commit

Permalink
CI: add basic framework
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerysong committed Oct 2, 2024
1 parent 0676227 commit 45cbb91
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 26 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: build
on:
push:
pull_request:

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install flake8
run: sudo pip install flake8

- name: Lint Python code
run: flake8 --max-line-length=160

check:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: apt update
run: sudo apt update

- name: Install dependencies
run: sudo apt install libbsd-dev liblua5.4-dev libmilter-dev libssl-dev

- name: Install Python dependencies
run: sudo pip install pytest

- name: Build OpenARC
run: |
autoreconf -fiv
CFLAGS='-Wall' ./configure
make -j4
- name: Check out miltertest
uses: actions/checkout@v4
with:
repository: flowerysong/miltertest
path: miltertest

- name: Build miltertest
run: |
autoreconf -fiv
./configure
make
working-directory: ${{ github.workspace }}/miltertest

- name: Test OpenARC
run: |
make check
- name: Build OpenARC with clang
run: |
make distclean
CC=clang ./configure
make -j4
- name: Build OpenARC without milter
run: |
make distclean
CC=clang ./configure --disable-filter
make -j4
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = libopenarc contrib docs openarc
SUBDIRS = libopenarc contrib docs openarc test
dist_doc_DATA = LICENSE LICENSE.Sendmail RELEASE_NOTES
dist_noinst_SCRIPTS = libtool

Expand Down
26 changes: 1 addition & 25 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -888,31 +888,6 @@ AC_SUBST(LIBOPENARC_INC)
AC_DEFINE_UNQUOTED([LIBOPENARC_FEATURE_STRING], "$LIBOPENARC_FEATURE_STRING",
[Feature string for printing])

#
# setup for testing
#

AC_ARG_ENABLE([live-testing],
AS_HELP_STRING([--disable-live-testing],
[disable tests that require Internet access]),
[live_tests="$enable_live_testing"], [live_tests="yes"])
AM_CONDITIONAL(LIVE_TESTS, test x"$live_tests" = x"yes")

#
# specify test socket
#

AC_ARG_WITH([test-socket],
AS_HELP_STRING([--with-test-socket],
[specify socket to use for all tests]),
[testsocket="$withval"], [testsocket=""])
AM_CONDITIONAL(TEST_SOCKET, test x"$testsocket" != x"")
if test x"$testsocket" != x""
then
TESTSOCKET=$testsocket
AC_SUBST(TESTSOCKET)
fi

#
# Platform Specific Configuration
#
Expand Down Expand Up @@ -983,5 +958,6 @@ AC_CONFIG_FILES([
openarc/openarc.8
openarc/openarc.conf.5
openarc/openarc.conf.simple
test/Makefile
])
AC_OUTPUT
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 4 additions & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXTRA_DIST = files pytest.ini *.py

check:
pytest -vv
62 changes: 62 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3

import os
import subprocess

import pytest


@pytest.fixture()
def private_key(scope='session'):
filepath = os.path.dirname(os.path.realpath(__file__))
filepath = os.path.join(filepath, 'files', 'private.key')
binargs = [
'openssl',
'genrsa',
'-out', filepath,
'2048',
]
subprocess.run(binargs)


@pytest.fixture()
def tool_path(scope='session'):
def _tool_path(tool):
binpath = os.path.dirname(os.path.realpath(__file__))
binpath = os.path.join(binpath, '..', tool)
return os.path.realpath(binpath)
return _tool_path


@pytest.fixture()
def milter_config(request, private_key):
base_path = os.path.join(request.fspath.dirname, 'files')
for candidate in [
request.fspath.basename, # test file
request.function.__name__, # test function
]:
fname = os.path.join(base_path, '.'.join([candidate, 'conf']))
if os.path.isfile(fname):
return fname

return os.path.join(base_path, 'milter.conf')


@pytest.fixture()
def milter_cmdline(tmp_path, tool_path, milter_config):
return [
tool_path('openarc/openarc'),
'-f',
'-v',
'-c', milter_config,
'-p', tmp_path.joinpath('milter.sock'),
]


@pytest.fixture()
def milter(milter_cmdline):
milter_proc = subprocess.Popen(milter_cmdline)

yield milter_proc

milter_proc.terminate()
3 changes: 3 additions & 0 deletions test/files/milter.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Domain example.com
KeyFile private.key
Selector elpmaxe
2 changes: 2 additions & 0 deletions test/files/test_config_fail.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Domain example.com
Selector elpmaxe
3 changes: 3 additions & 0 deletions test/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
console_output_style = count
log_file = pytest.log
13 changes: 13 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

import subprocess


def test_config(milter):
pass


def test_config_fail(milter_cmdline):
res = subprocess.run(milter_cmdline, capture_output=True, text=True, timeout=4)
assert res.returncode != 0
assert 'parameter "KeyFile" required when signing' in res.stderr

0 comments on commit 45cbb91

Please sign in to comment.