Skip to content

Commit 6ab0c51

Browse files
committed
add unit-tests
1 parent 8059a1a commit 6ab0c51

File tree

4 files changed

+95
-12
lines changed

4 files changed

+95
-12
lines changed

.github/actions/setup/action.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Setup Integration Test Environment'
2-
description: 'Common setup steps for integration and secure integration tests'
1+
name: 'Setup Test Environment'
2+
description: 'Common setup steps for unit, integration and secure integration tests'
33

44
inputs:
55
elastic_stack_version:
@@ -9,6 +9,14 @@ inputs:
99
description: 'Whether to use snapshot version'
1010
required: false
1111
default: 'false'
12+
docker_env:
13+
description: 'Docker environment file (e.g., dockerjdk21.env)'
14+
required: false
15+
default: ''
16+
integration:
17+
description: 'Enable integration testing'
18+
required: false
19+
default: 'false'
1220
secure_integration:
1321
description: 'Enable secure integration testing'
1422
required: false
@@ -35,42 +43,59 @@ runs:
3543
env:
3644
ELASTIC_STACK_VERSION: ${{ inputs.elastic_stack_version }}
3745
SNAPSHOT: ${{ inputs.snapshot }}
46+
DOCKER_ENV: ${{ inputs.docker_env }}
47+
INTEGRATION: ${{ inputs.integration }}
3848
SECURE_INTEGRATION: ${{ inputs.secure_integration }}
3949
ES_SSL_KEY_INVALID: ${{ inputs.es_ssl_key_invalid }}
4050
ES_SSL_SUPPORTED_PROTOCOLS: ${{ inputs.es_ssl_supported_protocols }}
4151
run: |
42-
echo "INTEGRATION=true" >> $GITHUB_ENV
4352
echo "LOG_LEVEL=info" >> $GITHUB_ENV
4453
echo "ELASTIC_STACK_VERSION=${ELASTIC_STACK_VERSION}" >> $GITHUB_ENV
4554
4655
if [ "${SNAPSHOT}" = "true" ]; then
4756
echo "SNAPSHOT=true" >> $GITHUB_ENV
4857
fi
49-
58+
59+
if [ -n "${DOCKER_ENV}" ]; then
60+
echo "DOCKER_ENV=${DOCKER_ENV}" >> $GITHUB_ENV
61+
fi
62+
63+
if [ "${INTEGRATION}" = "true" ]; then
64+
echo "INTEGRATION=true" >> $GITHUB_ENV
65+
fi
66+
5067
if [ "${SECURE_INTEGRATION}" = "true" ]; then
5168
echo "SECURE_INTEGRATION=true" >> $GITHUB_ENV
5269
fi
53-
70+
5471
if [ "${ES_SSL_KEY_INVALID}" = "true" ]; then
5572
echo "ES_SSL_KEY_INVALID=true" >> $GITHUB_ENV
5673
fi
57-
74+
5875
if [ -n "${ES_SSL_SUPPORTED_PROTOCOLS}" ]; then
5976
echo "ES_SSL_SUPPORTED_PROTOCOLS=${ES_SSL_SUPPORTED_PROTOCOLS}" >> $GITHUB_ENV
6077
fi
6178
6279
- name: Setup Docker Buildx
6380
uses: docker/setup-buildx-action@v3
6481

82+
- name: Bootstrap CI assets
83+
shell: bash
84+
run: |
85+
mkdir -p .ci
86+
curl -sL https://github.com/logstash-plugins/.ci/archive/1.x.tar.gz | \
87+
sh -c 'if tar --version 2>/dev/null | grep -q "GNU tar"; then
88+
TAR_KEEP="--skip-old-files"; TAR_WILDCARDS="--wildcards";
89+
else
90+
TAR_KEEP="-k"; TAR_WILDCARDS="";
91+
fi; tar -xzvf - $TAR_KEEP --strip-components=1 -C .ci $TAR_WILDCARDS "*Dockerfile*" "*docker*" "*.sh" "*logstash-versions*"'
92+
6593
- name: Run docker-setup.sh
6694
id: docker_setup
6795
shell: bash
6896
run: |
69-
set -e
70-
cd .ci
71-
wget -q https://raw.githubusercontent.com/elastic/logstash/main/.ci/docker-setup.sh -O .ci/docker-setup.shhttps://raw.githubusercontent.com/logstash-plugins/.ci/refs/heads/1.x/docker-setup.sh || exit 1
72-
chmod 755 docker-setup.sh
7397
bash .ci/docker-setup.sh
98+
echo "exit_code=$?" >> $GITHUB_OUTPUT
7499
continue-on-error: true
75100

76101
- name: Check if test should be skipped

.github/workflows/integration-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ jobs:
3434
with:
3535
elastic_stack_version: ${{ matrix.elastic_stack_version }}
3636
snapshot: ${{ matrix.snapshot }}
37+
integration: true
3738

3839
- name: Run integration tests
3940
if: steps.setup.outputs.skip != 'true'
40-
run: .ci/docker-run.sh
41+
run: |
42+
bash .ci/docker-run.sh
4143
4244
# NOTE: no cleanup needed when running on ephemeral runners

.github/workflows/secure-integration-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737

3838
- name: Run secure integration tests
3939
if: steps.setup.outputs.skip != 'true'
40-
run: .ci/docker-run.sh
40+
run: |
41+
bash .ci/docker-run.sh
4142
4243
# NOTE: no cleanup needed when running on ephemeral runners

.github/workflows/unit-tests.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
jobs:
11+
unit-tests:
12+
name: Unit Test - ES ${{ matrix.elastic_stack_version }} ${{ matrix.snapshot && '(Snapshot)' || '' }}
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
elastic_stack_version:
18+
- "9.current"
19+
- "9.previous"
20+
- "8.current"
21+
- "8.previous"
22+
- "7.current"
23+
docker_env: ["dockerjdk21.env"]
24+
snapshot: [false]
25+
exclude:
26+
# 7.x doesn't support JDK 21, use default JDK
27+
- elastic_stack_version: "7.current"
28+
docker_env: "dockerjdk21.env"
29+
include:
30+
# 7.current with default JDK
31+
- elastic_stack_version: "7.current"
32+
docker_env: ""
33+
snapshot: false
34+
# Main snapshot with JDK 21
35+
- elastic_stack_version: "main"
36+
docker_env: "dockerjdk21.env"
37+
snapshot: true
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v6
42+
43+
- name: Setup test environment
44+
id: setup
45+
uses: ./.github/actions/setup
46+
with:
47+
elastic_stack_version: ${{ matrix.elastic_stack_version }}
48+
snapshot: ${{ matrix.snapshot || false }}
49+
docker_env: ${{ matrix.docker_env || '' }}
50+
51+
- name: Run unit tests
52+
if: steps.setup.outputs.skip != 'true'
53+
run: bash .ci/docker-run.sh
54+
55+
# NOTE: no cleanup needed when running on ephemeral runners

0 commit comments

Comments
 (0)