Test container with BTest instead of container-structure-tests

This patch replaces the container-strucuture-tests for the Zeek
container with a BTest-driven approach to provide a more familiar
experience. In addtion to `python3` for `btest` we also rely on `make`
being available in Github-hosted runners which at least currently seems
to be hold (probably pulled in as a dependency of CMake which is
officially included, see
https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md).
This commit is contained in:
Christian Kreibich 2021-09-22 16:37:52 -07:00 committed by Benjamin Bannier
parent ddae1398f1
commit d6c80f6d2c
8 changed files with 81 additions and 43 deletions

View file

@ -36,12 +36,8 @@ jobs:
load: true load: true
tags: ${{ env.TEST_TAG }} tags: ${{ env.TEST_TAG }}
# Run tests on the just created image. - name: Run btests
- name: Run tests run: make -C docker/btest
uses: plexsystems/container-structure-test-action@v0.2.0
with:
image: ${{ env.TEST_TAG }}
config: docker/container-structure-test.yaml
- name: Get Version - name: Get Version
id: version id: version
@ -84,3 +80,11 @@ jobs:
push: true push: true
tags: | tags: |
zeekurity/${{ steps.target.outputs.tag}} zeekurity/${{ steps.target.outputs.tag}}
- name: Preserve artifacts
uses: actions/upload-artifact@v2
if: failure()
with:
name: docker-btest
path: docker/btest/.tmp
if-no-files-found: ignore

View file

@ -6,3 +6,7 @@ VERSION := $$(cat ../VERSION)
all: all:
@docker build -t zeek:$(VERSION) -f Dockerfile .. @docker build -t zeek:$(VERSION) -f Dockerfile ..
@docker tag zeek:$(VERSION) zeek:latest
test:
@TEST_TAG=zeek:$(VERSION) $(MAKE) -C btest

3
docker/btest/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.tmp
.btest.failed.dat
diag.log

View file

@ -0,0 +1,20 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
zeek version xxx
XXX
[sources]
zeek = https://github.com/zeek/packages
[paths]
state_dir = /usr/local/zeek/var/lib/zkg
script_dir = /usr/local/zeek/share/zeek/site
plugin_dir = /usr/local/zeek/lib/zeek/plugins
bin_dir = /usr/local/zeek/bin
zeek_dist =
[templates]
default = https://github.com/zeek/package-template
Installing "zeek/sethhall/domain-tld"
Installed "zeek/sethhall/domain-tld" (XXX)
Loaded "zeek/sethhall/domain-tld"

11
docker/btest/Makefile Normal file
View file

@ -0,0 +1,11 @@
DIAG=diag.log
BTEST=../../auxil/btest/btest
all: cleanup btest-verbose
# Showing all tests.
btest-verbose:
@$(BTEST) -d -j -f $(DIAG)
cleanup:
@rm -f $(DIAG)

13
docker/btest/btest.cfg Normal file
View file

@ -0,0 +1,13 @@
[btest]
TestDirs = docker
TmpDir = %(testbase)s/.tmp
BaselineDir = %(testbase)s/Baseline
IgnoreDirs = .tmp
IgnoreFiles = *.tmp *.swp #* *.trace .DS_Store
MinVersion = 0.63
[environment]
LC_ALL=C
PATH=%(testbase)s/../../auxil/btest:%(default_path)s
TEST_IMAGE=${TEST_TAG:-zeek:latest}
TZ=UTC

View file

@ -0,0 +1,20 @@
# @TEST-REQUIRES: docker inspect ${TEST_TAG:-zeek:latest}
# @TEST-EXEC: bash -euxo pipefail %INPUT >output
# @TEST-EXEC: btest-diff output
TEST_TAG=${TEST_TAG:-zeek:latest}
# Check that `zeek` can be run.
docker run --rm "${TEST_TAG}" zeek -v | sed 's/\(zeek version\) .*/\1 xxx/'
# Check that this is a release build.
docker run --rm "${TEST_TAG}" zeek-config --build_type | grep -q 'release'
# Check that `btest` can be run.
docker run --rm "${TEST_TAG}" btest --version | sed 's/^[0-9].*/XXX/g'
# Check that the zkg config looks valid.
docker run --rm "${TEST_TAG}" zkg config
# Check that a plugin can be installed. We pick any plugin with minimal deps here.
docker run --rm "${TEST_TAG}" zkg install --force sethhall/domain-tld | sed 's/(.*)/(XXX)/'

View file

@ -1,37 +0,0 @@
# See the file "COPYING" in the main distribution directory for copyright.
# This file contains a test configuration for
# https://github.com/GoogleContainerTools/container-structure-test.
schemaVersion: 2.0.0
commandTests:
- name: zeek can be run
command: zeek
args: ["-v"]
expectedOutput: ["^zeek version .*"]
- name: is release build
command: zeek-config
args: ["--build_type"]
expectedOutput: ["release"]
- name: btest can be run
command: btest
args: ["--version"]
expectedOutput: ["\\d\\.\\d"]
- name: valid zkg config
command: zkg
args: ["config"]
# Just validate that we some some valid entry here.
expectedOutput: ["state_dir = /usr/local/zeek/var/lib/zkg"]
- name: plugin can be installed
command: zkg
# We pick any plugin with minimal deps here.
args: ["install", "--force", "sethhall/domain-tld"]
expectedOutput:
- "Installing \"zeek/sethhall/domain-tld\""
- "Installed \"zeek/sethhall/domain-tld\" (.*)"
- "Loaded \"zeek/sethhall/domain-tld\""