Skip to content

Commit cdeadb0

Browse files
authored
Merge pull request #180 from whyscream/simpler-local-testing
Add script to run tests inside a docker container
2 parents 0652d66 + 2ea2c09 commit cdeadb0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.github/workflows/run_tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ jobs:
44
runs-on: ubuntu-latest
55

66
steps:
7-
- uses: actions/checkout@v2
7+
- uses: actions/checkout@v4
88
with:
99
submodules: true
1010
- uses: ruby/setup-ruby@v1
1111
with:
12-
ruby-version: 3.2
12+
ruby-version: '3.2'
1313
- run: gem install jls-grok minitest
1414
- run: ruby test/test.rb

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Tests
3636

3737
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` :-).
3838

39-
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`.
39+
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.
4040

4141
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.
4242

runtests.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
5+
DOCKERIMAGE="postfix-grok-patterns-runtests"
6+
VOLUMEPATH="/runtests"
7+
8+
git submodule update --init
9+
10+
docker build --tag ${DOCKERIMAGE} - <<EOF
11+
FROM ruby:slim
12+
RUN gem install jls-grok minitest
13+
EOF
14+
15+
docker run --volume $(pwd):"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb"

0 commit comments

Comments
 (0)