Skip to content

Commit

Permalink
Configure petstore SUT in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Jul 12, 2024
1 parent bb63bef commit 3201cc3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ jobs:
java-version: '8'
cache: 'maven'

- name: Launch Petstore
if: ${{ matrix.scope == 'Petstore' }}
working-directory: ./sut-petstore
run: |
mvn package -DskipTests=true -ntp
docker build -t swagger-petstore .
docker run -d -p 8081:8080 --name swagger-petstore swagger-petstore
chmod u+x ../setup/wait-container-ready.sh
../setup/wait-container-ready.sh swagger-petstore "public ResponseContext findPetsByCategoryAndStatus"
- run: docker ps

- name: Rules cache
id: rules-cache
uses: actions/[email protected]
Expand All @@ -37,10 +48,13 @@ jobs:
key: cache-${{ matrix.scope }}-v1-${{ github.run_id }}
restore-keys: cache-${{ matrix.scope }}-v1-

- name: Test and aggregate surefire report
- name: Test All
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn test -pl st-tdg-test -Dtest=**/*Local* -Dmaven.test.failure.ignore=true -U --no-transfer-progress
run: mvn test -pl st-tdg-test -Dtest=**/*${{ matrix.scope }}* -Dmaven.test.failure.ignore=true -U --no-transfer-progress

- if: ${{ matrix.scope == 'Petstore' }}
run: docker logs swagger-petstore > st-tdg-test/target/docker-petstore-server.log

- name: Generate report checks
if: always()
Expand Down
2 changes: 1 addition & 1 deletion setup/run-swagger-petstore.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo on
SET PETSTORE_DIR=%~dp0%\..\swagger-petstore-main-fork
SET PETSTORE_DIR=%~dp0%\..\sut-petstore
cd %PETSTORE_DIR%
cmd /c mvn package -DskipTests=true
docker build -t swagger-petstore .
Expand Down
19 changes: 19 additions & 0 deletions setup/wait-container-ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
#Sample approach to wait until a container is ready
#by looking for a string in container log
container=$1
target=$2

attempt=0
while [ $attempt -le 30 ]; do
attempt=$(( $attempt + 1 ))
echo "Waiting for container '$container' ready (attempt: $attempt)..."
result=$(docker logs --tail 20 $container)
if grep -q "$target" <<< $result ; then
echo "Container '$container' is ready!"
exit 0
fi
sleep 2
done
echo "ERROR: Container '$container' is not ready after maximum number of attempts"
exit 1

0 comments on commit 3201cc3

Please sign in to comment.