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_NAME="your-application"
# 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 /var/log/redtest/\${PACKAGE_NAME}
# Copy the logs from source to the location specified by redtest
cp -a /path/to/your/logs_dir/on_target/. /var/log/redtest/\${PACKAGE_NAME}/
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_NAME
with the real package name - 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_NAME="helloworld-api"
# 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 "/var/log/redtest/${PACKAGE_NAME}/" | tee "/tmp/tests_logs/tests_helloworld.tap"
# Create the directory where the logs need to be
mkdir -p /var/log/redtest/${PACKAGE_NAME}
# Copy the logs from source to the location specified by redtest
cp -a /tmp/tests_logs/. /var/log/redtest/${PACKAGE_NAME}/