diff --git a/tests/basic-fail-test/runtest.sh b/tests/basic-fail-test/runtest.sh new file mode 100644 index 0000000..a7f2a1c --- /dev/null +++ b/tests/basic-fail-test/runtest.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Running a command that should fail" + +false + diff --git a/tests/basic-fix-failed-test/runtest.sh b/tests/basic-fix-failed-test/runtest.sh new file mode 100644 index 0000000..11e0a78 --- /dev/null +++ b/tests/basic-fix-failed-test/runtest.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +test_log="/tmp/artifacts/test.log" + +echo "Make sure test log has failed test" +grep -e "^FAIL" ${test_log} + +echo "Change FAIL results to PASS" +sed -i -e 's/^FAIL/PASS/g' ${test_log} + diff --git a/tests/basic-simple-test/runtest.sh b/tests/basic-simple-test/runtest.sh new file mode 100644 index 0000000..87c587b --- /dev/null +++ b/tests/basic-simple-test/runtest.sh @@ -0,0 +1,5 @@ +#!/bin/bash +PACKAGE="bash" + +echo "Using $PACKAGE version:" +rpm -q $PACKAGE diff --git a/tests/basic-verify-test/runtest.sh b/tests/basic-verify-test/runtest.sh new file mode 100644 index 0000000..0ce4d8c --- /dev/null +++ b/tests/basic-verify-test/runtest.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Make sure test log from previous tests were created +ls ../artifacts/test.log + +# Previous test log should be available on /tmp/artifacts +ls /tmp/artifacts/test.log + +# Clean up log directories +rm -rf ../artifacts diff --git a/tests/beakerlib-fail-test/runtest.sh b/tests/beakerlib-fail-test/runtest.sh new file mode 100644 index 0000000..f1e63f7 --- /dev/null +++ b/tests/beakerlib-fail-test/runtest.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + # Running a command that should fail + rlRun "false" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/beakerlib-fix-failed-test/runtest.sh b/tests/beakerlib-fix-failed-test/runtest.sh new file mode 100644 index 0000000..ff33b8a --- /dev/null +++ b/tests/beakerlib-fix-failed-test/runtest.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +test_log="/tmp/artifacts/test.log" + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Fix beakerlib failed test" + # Make sure test log has failed test + rlRun "grep -e '^FAIL' ${test_log}" + # Change FAIL results to PASS + rlRun "sed -i -e 's/^FAIL/PASS/g' ${test_log}" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + + diff --git a/tests/beakerlib-simple-test/runtest.sh b/tests/beakerlib-simple-test/runtest.sh new file mode 100644 index 0000000..fb77e47 --- /dev/null +++ b/tests/beakerlib-simple-test/runtest.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + rlRun "ls /" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/beakerlib-verify-test/runtest.sh b/tests/beakerlib-verify-test/runtest.sh new file mode 100644 index 0000000..fb925c3 --- /dev/null +++ b/tests/beakerlib-verify-test/runtest.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="standard-test-roles" + +rlJournalStart + rlPhaseStartTest "Check output files" + # Previous test log should have created local artifacts + rlRun "ls ../artifacts/test.log" + # Previous test log should be available on /tmp/artifacts + rlRun "ls /tmp/artifacts/test.log" + rlPhaseEnd + rlPhaseStartCleanup + rlRun "rm -rf ../artifacts" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/rhts-fail-test/Makefile b/tests/rhts-fail-test/Makefile new file mode 100644 index 0000000..05cafbe --- /dev/null +++ b/tests/rhts-fail-test/Makefile @@ -0,0 +1,34 @@ +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Bruno Goncalves " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: fail rhts test role" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/rhts-fail-test/runtest.sh b/tests/rhts-fail-test/runtest.sh new file mode 100644 index 0000000..f1e63f7 --- /dev/null +++ b/tests/rhts-fail-test/runtest.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + # Running a command that should fail + rlRun "false" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/rhts-fix-failed-test/runtest.sh b/tests/rhts-fix-failed-test/runtest.sh new file mode 100644 index 0000000..11e0a78 --- /dev/null +++ b/tests/rhts-fix-failed-test/runtest.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +test_log="/tmp/artifacts/test.log" + +echo "Make sure test log has failed test" +grep -e "^FAIL" ${test_log} + +echo "Change FAIL results to PASS" +sed -i -e 's/^FAIL/PASS/g' ${test_log} + diff --git a/tests/rhts-simple-test/Makefile b/tests/rhts-simple-test/Makefile new file mode 100644 index 0000000..d49515c --- /dev/null +++ b/tests/rhts-simple-test/Makefile @@ -0,0 +1,34 @@ +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Bruno Goncalves " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: simple rhts test role" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/rhts-simple-test/runtest.sh b/tests/rhts-simple-test/runtest.sh new file mode 100644 index 0000000..fb77e47 --- /dev/null +++ b/tests/rhts-simple-test/runtest.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + rlRun "ls /" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/rhts-verify-test/runtest.sh b/tests/rhts-verify-test/runtest.sh new file mode 100644 index 0000000..0ce4d8c --- /dev/null +++ b/tests/rhts-verify-test/runtest.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Make sure test log from previous tests were created +ls ../artifacts/test.log + +# Previous test log should be available on /tmp/artifacts +ls /tmp/artifacts/test.log + +# Clean up log directories +rm -rf ../artifacts diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..3d8526f --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,4 @@ +--- +- import_playbook: tests_basic.yml +- import_playbook: tests_beakerlib.yml +- import_playbook: tests_rhts.yml diff --git a/tests/tests_basic.yml b/tests/tests_basic.yml new file mode 100644 index 0000000..cee6b2c --- /dev/null +++ b/tests/tests_basic.yml @@ -0,0 +1,54 @@ +# Tests for basic role +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - atomic + - classic + - container + tests: + - basic-simple-test + - basic-parameters-test: + dir: ./ + run: echo "check parameters on basic role" | grep "check parameters on basic role" + required_packages: + - iscsi-initiator-utils # test if we can install packages + +# Tests to verify basic role execution +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - atomic + - classic + - container + tests: + - basic-verify-test + +- import_playbook: tests_verify_local.yml + +#### Make sure the role behaves correctly if test fails +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - atomic + - classic + - container + tests: + - basic-fail-test + ignore_errors: yes + +# Tests to verify failed role execution +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - atomic + - classic + - container + tests: + - basic-fix-failed-test + - basic-verify-test + +- import_playbook: tests_verify_local.yml diff --git a/tests/tests_beakerlib.yml b/tests/tests_beakerlib.yml new file mode 100644 index 0000000..01dd883 --- /dev/null +++ b/tests/tests_beakerlib.yml @@ -0,0 +1,51 @@ +# Tests for beakerlib role +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - atomic + - classic + - container + tests: + - beakerlib-simple-test + required_packages: + - iscsi-initiator-utils # test if we can install packages + +# Tests to verify beakerlib role execution +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - atomic + - classic + - container + tests: + - beakerlib-verify-test + +- import_playbook: tests_verify_local.yml + +#### Make sure the role behaves correctly if test fails +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - atomic + - classic + - container + tests: + - beakerlib-fail-test + ignore_errors: yes + +# Tests to verify failed role execution +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - atomic + - classic + - container + tests: + - beakerlib-fix-failed-test + - beakerlib-verify-test + +- import_playbook: tests_verify_local.yml diff --git a/tests/tests_rhts.yml b/tests/tests_rhts.yml new file mode 100644 index 0000000..a710253 --- /dev/null +++ b/tests/tests_rhts.yml @@ -0,0 +1,44 @@ +# Tests for rhts role only runs on classic tag +- hosts: localhost + roles: + - role: standard-test-rhts + tags: + - classic + tests: + - rhts-simple-test + required_packages: + - iscsi-initiator-utils # test if we can install packages + +# Tests to verify rhts role execution +# Using basic role becasue it is easier to know where the artifacts should be created +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - rhts-verify-test + +- import_playbook: tests_verify_local.yml + +#### Make sure the role behaves correctly if test fails +- hosts: localhost + roles: + - role: standard-test-rhts + tags: + - classic + tests: + - rhts-fail-test + ignore_errors: yes + +# Tests to verify failed role execution +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - rhts-fix-failed-test + - rhts-verify-test + +- import_playbook: tests_verify_local.yml diff --git a/tests/tests_verify_local.yml b/tests/tests_verify_local.yml new file mode 100644 index 0000000..8c28423 --- /dev/null +++ b/tests/tests_verify_local.yml @@ -0,0 +1,15 @@ +# Run after role test, check if role created expected files +- hosts: localhost + tags: + - atomic + - classic + - container + tasks: + - name: check if artifacts is created locally + shell: ls artifacts/test.log + delegate_to: localhost + # remove artifacts directory after check so it does not affect other tests + - name: remove artifacts directory + shell: rm -rf artifacts + delegate_to: localhost +