redtests in the applications sources

The first thing to do to enable the redtests for your project is to create the redtest directory in your sources repository. Inside this directory, a run-redtest script is needed. This is the script that the redpesk infrastructure will run to run your tests! To do so, use the list of commands here below.

# Go to your local sources repository
cd /path/to/your_application

# Create a redtest/ directory
mkdir redtest

# Create the run-redtest script from a template
cat << EOF > ./redtest/run-redtest
#!/bin/bash

# When this script will be run, the packages your-application.rpm and your-application-redtest.rpm
# would have been installed on the target

PACKAGE_REDTEST_NAME="your-application-redtest"

# Do whatever you want

# Run your tests
# To be filled by you! Remember, the log file needs to be in ".tap" format

# Create the directory where the logs need to be
mkdir -p /usr/lib/\${PACKAGE_REDTEST_NAME}/redtest/logs

# Copy the logs from source to the location specified by redtest
cp -a /path/to/your/logs_dir/on_target/. /usr/lib/\${PACKAGE_REDTEST_NAME}/redtest/logs/
EOF

# Set the run-redtest file as executable
chmod +x ./redtest/run-redtest

At this point, your project has the right structure for the tests, but the last piece of work is for you! Indeed, you need to adapt the run-redtest template given in the example to your needs:

  • Modify the value of PACKAGE_REDTEST_NAME with the real package name, ending with -redtest
  • Fill the # Run your tests part with the appropriate commands to run your tests
  • Modify the /path/to/your/logs_dir/on_target/. path with the directory containing the logs file(s) after the tests run

Do not forget that:

  • During the tests, it is better if the stdout respects the T.A.P. format
  • At the end of the tests, the generated report must respect the T.A.P. format and must have the “.tap” extension

Here below an example of run-redtest file for a python application.

#!/bin/bash

# When this script will be run, the packages your-application.rpm and your-application-redtest.rpm
# would have been installed on the target

PACKAGE_REDTEST_NAME="helloworld-api-redtest"

# Do whatever you want

# Export environment variable in order to ask python to not buffer the lines
export PYTHONUNBUFFERED=1

# Start the helloworld service
systemctl start redtesthelloapi.service

# Run your tests
# To be filled by you! Remember, the log file needs to be in ".tap" format
pytest-3 --tap-stream "/usr/lib/${PACKAGE_REDTEST_NAME}/redtest/" | tee "/tmp/tests_logs/tests_helloworld.tap"

# Create the directory where the logs need to be
mkdir -p /usr/lib/${PACKAGE_REDTEST_NAME}/redtest/logs

# Copy the logs from source to the location specified by redtest
cp -a /tmp/tests_logs/. /usr/lib/${PACKAGE_REDTEST_NAME}/redtest/logs/