Skip to content

Commit

Permalink
Add workflow to run bats tests (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm authored Jul 18, 2024
1 parent 2940deb commit 82aad10
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Bats Test

on:
pull_request:
workflow_dispatch:

jobs:
test:
strategy:
matrix:
testname: [0-otelify, 1-apps, 2-integration]
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v2

- name: Set up Bats and Bats-support
run: |
sudo apt-get update
sudo apt-get install -y bats bats-support bats-assert
- name: Run Bats tests
run: |
export INTEGRATION_TEST_URL="https://github.com/cisco-open/"
bats --filter-tags '!integration:dotnet' test/${{ matrix.testname }}.bats
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ RUN \
--update \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
add \
nodejs=20.12.1-r0 \
openjdk11=11.0.23_p9-r0 \
nodejs-current=21.7.3-r0 \
openjdk11=11.0.24_p8-r0 \
curl=8.5.0-r0 \
npm=10.2.5-r0 \
ca-certificates=20240226-r0 \
dotnet8-sdk=8.0.106-r0 \
dotnet8-sdk=8.0.107-r0 \
&& update-ca-certificates
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ if [ ${WITH_INTEGRATION} -eq 1 ]; then
${DOCKER_COMMAND} build -t "$FULL_IMAGE_NAME" .
fi

${DOCKER_COMMAND} run -it -e WITH_INTEGRATION="${WITH_INTEGRATION}" -e INTEGRATION_TEST_URL="${INTEGRATION_TEST_URL}" -e BATS_LIB_PATH=/usr/lib/bats -v "${PWD}:/code" "${FULL_IMAGE_NAME}" test
${DOCKER_COMMAND} run -it -e WITH_INTEGRATION="${WITH_INTEGRATION}" -e INTEGRATION_TEST_URL="${INTEGRATION_TEST_URL}" -e BATS_LIB_PATH=/usr/lib/bats -v "${PWD}:/code" "${FULL_IMAGE_NAME}" -x --verbose-run test
2 changes: 1 addition & 1 deletion test/0-otelify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ get_usage_line() {

@test "can run otelify.sh" {
run get_usage_line
assert_output 'Usage: /code/test/../otelify.sh [options] <application>'
assert_output "Usage: ${OTELIFY_SHELL_SCRIPT_PATH}/otelify.sh [options] <application>"
}

get_debug_line() {
Expand Down
4 changes: 3 additions & 1 deletion test/2-integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ teardown() {
# rm -rf ${APP_DIR}
}

#bats test_tags=integration:nodejs, nodejs
@test "can otelify nodejs applications" {
run otelify.sh -- node "${APP_DIR}/app.js"
assert_output --partial 'traceId: '
}

#bats test_tags=integration:java, java
@test "can otelify java applications" {
OLD_PWD=${PWD}
cd "${APP_DIR}"
Expand All @@ -61,7 +63,7 @@ teardown() {
assert_output --partial 'io.opentelemetry.exporter.logging.LoggingSpanExporter'
}


#bats test_tags=integration:dotnet, dotnet
@test "can otelify dotnet applications" {
run otelify.sh -d -- dotnet run --project "${APP_DIR}"
assert_output --partial 'Activity.TraceId:'
Expand Down
1 change: 1 addition & 0 deletions test/test_helper/common-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _common_setup() {
bats_load_library 'bats-assert'
DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"
PATH="$DIR/../:$PATH"
export OTELIFY_SHELL_SCRIPT_PATH="$DIR/.."
export OTELIFY_DIRECTORY="/tmp/otelify-test-dir"
}

Expand Down

0 comments on commit 82aad10

Please sign in to comment.