Skip to content

Commit

Permalink
improve test execution handling in workflow and integration test play…
Browse files Browse the repository at this point in the history
…book (#50)
  • Loading branch information
ykim-akamai authored May 15, 2024
1 parent 3d066cb commit cb2a92d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
26 changes: 5 additions & 21 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,23 @@ jobs:

- name: run e2e test
run: |
if ! make e2e ; then
echo "EXIT_STATUS=1" >> $GITHUB_ENV
fi
make e2e
env:
CLEANUP_TEST_LINODE_INSTANCE: true
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

- name: Copy report.xml from hack directory to root directory
run: |
cp hack/*_go_metadata_test_report.xml .

- name: Add additional information to XML report
- name: Upload test results
if: always()
run: |
cp hack/*_go_metadata_test_report.xml .
filename=$(ls | grep -E '^[0-9]{12}_go_metadata_test_report\.xml$')
python tod_scripts/add_to_xml_test_report.py \
--branch_name "${GITHUB_REF#refs/*/}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"
- name: Upload test results
run: |
filename=$(ls | grep -E '^[0-9]{12}_go_metadata_test_report\.xml$')
sync
python tod_scripts/test_report_upload_script.py "${filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

- name: Test Execution Status Handler
run: |
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Test execution contains failure(s)"
exit $EXIT_STATUS
else
echo "Tests passed!"
fi
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ test-deps:
e2e:
ANSIBLE_HOST_KEY_CHECKING=False ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -v --extra-vars="debug=${LINODE_DEBUG} ssh_pubkey_path=${TEST_PUBKEY} cleanup_linode=${CLEANUP_TEST_LINODE_INSTANCE}" ./hack/run-e2e.yml

# Define the timestamp and dynamic report filename
REPORT_TIMESTAMP := $(shell date +'%Y%m%d%H%M')
export REPORT_FILENAME := $(REPORT_TIMESTAMP)_go_metadata_test_report.xml
export REPORT_FILENAME := $(shell date +'%Y%m%d%H%M')_go_metadata_test_report.xml

# Runs the E2E test suite locally.
# NOTE: E2E tests must be run from within a Linode.
# NOTE: E2E tests must be run from within a Linode. Will also create a report in hack directory
e2e-local:
cd test/integration && make e2e-local

Expand Down
17 changes: 16 additions & 1 deletion hack/run-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,22 @@
source .test.env && \
make e2e-local
register: run_tests
ignore_errors: true

- name: Set playbook_failed based on E2E test result
set_fact:
playbook_failed: "{{ run_tests.rc != 0 }}"
vars:
playbook_failed: false # make it default to false if no failure detected
when: run_tests is defined and run_tests.rc is defined

- name: Find report.xml file on remote server
find:
paths: "~/go-metadata-{{ run_id }}/test/integration"
patterns: "*_go_metadata_test_report.xml"
file_type: file
register: report_files
ignore_errors: true # Continue to next step if no files are found

- name: Extract filename from the found files
set_fact:
Expand All @@ -146,7 +155,13 @@
dest: "./"
flat: yes
remote_src: yes
ignore_errors: yes
ignore_errors: true

# Fail the playbook if necessary
- name: Fail the playbook if E2E test suite failed
fail:
msg: "E2E test suite failed, Check step above.."
when: playbook_failed

rescue:
- debug:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e2e-local:
go test -v ./... | go-junit-report -set-exit-code > $(REPORT_FILENAME)
go test -v ./... | go-junit-report -set-exit-code -iocopy -out $(REPORT_FILENAME)

0 comments on commit cb2a92d

Please sign in to comment.