From 2ea2c09c94ecdf5742ffb23c4fb049036014edfb Mon Sep 17 00:00:00 2001 From: Tom Hendrikx Date: Wed, 11 Oct 2023 18:06:12 +0200 Subject: [PATCH] Add script to run tests inside a docker container This helps tremendously with local testing. --- .github/workflows/run_tests.yml | 4 ++-- README.md | 2 +- runtests.sh | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100755 runtests.sh diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index f178628..6617931 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -4,11 +4,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.2 + ruby-version: '3.2' - run: gem install jls-grok minitest - run: ruby test/test.rb diff --git a/README.md b/README.md index 0f9dfa1..717ec43 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Tests In the `test/` directory, there is a test suite that tries to make sure that no previously supported log line will break because of changing common patterns and such. It also returns results a lot faster than doing `sudo service logstash restart` :-). -The test suite needs the patterns provided by Logstash, you can easily pull these from github by running `git submodule update --init`. To run the test suite, you also need `ruby 2.2` or higher, and the `jls-grok` and `minitest` gems. Then simply execute `ruby test/test.rb`. +The test suite needs the patterns provided by Logstash, you can easily pull these from github by running `git submodule update --init`. To run the test suite, you need a recent version of `ruby` (`2.6` or newer should work), and the `jls-grok` and `minitest` gems. Then simply execute `ruby test/test.rb`. NOTE: The whole test process can now be executed inside a docker container, simply by running the `runtests.sh` script. Adding new test cases can easily be done by creating new yaml files in the test directory. Each file specifies a grok pattern to validate, a sample log line, and a list of expected results. diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..08b1280 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -eux + +DOCKERIMAGE="postfix-grok-patterns-runtests" +VOLUMEPATH="/runtests" + +git submodule update --init + +docker build --tag ${DOCKERIMAGE} - <