The main concept is that all tests should use the image as is without any 'internal' go-related features. We, like users, receive the image and we are going to check what we've got.
The project has been started in Java as POC, however, I'm thinking about porting to python which is more suitable lang for the Ansible-oriented stack. Kindly ask you to raise the issue in case of any suggestions/bugs.
-
Download the latest shaded dist from https://github.com/dgroup/docker-unittests/releases:
wget https://github.com/dgroup/docker-unittests/releases/download/s1.1.1/docker-unittests-app-1.1.1.jar
-
Define an *.yml file with tests.
version: 1.1 setup: - apt-get update - apt-get install -y tree tests: - assume: java version is 1.9, Debian build cmd: java -version output: contains: - openjdk version "9.0.1" - build 9.0.1+11-Debian - assume: curl version is 7.xxx cmd: curl --version output: startsWith: curl 7. matches: - "^curl\\s7.*\\n.*\\nProtocols.+ftps.+https.+telnet.*\\n.*\\n$" contains: - AsynchDNS IDN IPv6 Largefile GSS-API - assume: Setup section installed `tree` cmd: tree --version output: contains: ["Steve Baker", "Florian Sesser"]
-
Run tests for image
java -jar docker-unittests.jar -f image-tests.yml -i openjdk:9.0.1-11
- Use -o xml option in order to receive the testing report in xml format
java -jar docker-unittests.jar -f image-tests.yml -i openjdk:9.0.1-11 -o xml
- Define the
test.yml
with tests.version: 1.1 tests: - assume: "java version is 1.9, Debian build" cmd: "java -version" output: contains: - openjdk version "9.0.1" - build 9.0.1+11-Debian # The test below will fail due to wrong version of curl. - assume: "curl version is 8000" cmd: "curl --version" output: startsWith: "curl 8000" matches: - "^curl\\s7.*\\n.*\\nProtocols.+ftps.+https.+telnet.*\\n.*\\n$" contains: - "AsynchDNS IDN IPv6 Largefile GSS-API"
- Define an
test.sh
with testing command#!/usr/bin/env bash set -e echo Testing has been started java -jar docker-unittests.jar -f test.yml -i openjdk:9.0.1-11 echo This line will not be executed as testing will fail
- Run the
test.sh
Predicate | Multiple | YML tag format |
---|---|---|
startsWith | No | startsWith: "curl 8000" |
endsWith | No | endsWith: "VM (build 25.181-b13, mixed mode)" |
equals | No | equals: "curl 7.54.0" |
contains | Yes | contains: ["7.54", "LibreSSL", "pop3 pop3s"] |
matches | Yes | matches: ["^curl\\s7.*\\n.*\\nProtocols.+ftps.+https.+.*\\n$"] |