Skip to content

Commit

Permalink
Merge pull request #180 from whyscream/simpler-local-testing
Browse files Browse the repository at this point in the history
Add script to run tests inside a docker container
  • Loading branch information
whyscream committed Oct 11, 2023
2 parents 0652d66 + 2ea2c09 commit cdeadb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.

Expand Down
15 changes: 15 additions & 0 deletions 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} - <<EOF
FROM ruby:slim
RUN gem install jls-grok minitest
EOF

docker run --volume $(pwd):"${VOLUMEPATH}" --workdir ${VOLUMEPATH} ${DOCKERIMAGE} sh -c "ruby test/test.rb"

0 comments on commit cdeadb0

Please sign in to comment.