From b8ab72e1c4dea0ac64a0dafef5a4a39918fe4230 Mon Sep 17 00:00:00 2001 From: Petr Šplíchal Date: May 09 2019 12:09:52 +0000 Subject: Update test examples with results.yml [fix #3] Include 'results.yml' file creation in examples showing how to write and wrap tests. Is part of fixing #3. --- diff --git a/modules/ROOT/pages/tests.adoc b/modules/ROOT/pages/tests.adoc index 73d617e..a3866c2 100644 --- a/modules/ROOT/pages/tests.adoc +++ b/modules/ROOT/pages/tests.adoc @@ -129,14 +129,20 @@ Lets place the following example in `test_pid_1.yml` file. - name: Test block block: - name: Test that /proc/1 exists - shell: ls /proc > /tmp/test.log && grep -qw 1 /tmp/test.log + shell: | + ls /proc > /tmp/test.log || exit 1 + grep -qw 1 /tmp/test.log && result=pass || result=fail + echo -e "results:\n- {result: $result, test: proc}" > /tmp/results.yml always: - name: Pull out the artifacts fetch: dest: "{{ artifacts }}/" - src: "/tmp/test.log" + src: "{{ item }}" flat: yes + with_items: + - /tmp/test.log + - /tmp/results.yml ---- All tests have an artifacts directory where they place their output. @@ -231,14 +237,19 @@ We can write an Ansible wrapper for this script like this in `test_simple.yml`: - name: Test block block: - name: Execute the tests - shell: exec > /tmp/test.log 2>&1 && /usr/local/bin/test-simple + shell: | + /usr/local/bin/test-simple &> /tmp/test.log && result=pass || result=fail + echo -e "results:\n- {result: $result, test: simple}" > /tmp/results.yml always: - name: Pull out the logs fetch: dest: "{{ artifacts }}/" - src: "/tmp/test.log" + src: "{{ item }}" flat: yes + with_items: + - /tmp/test.log + - /tmp/results.yml ---- All tests have an artifacts directory where they place their output.