From 92b5b84c0dcbeb22528e336ae7740d5aff1656cd Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Thu, 26 Mar 2020 11:21:13 +1100
Subject: [PATCH] run_functests: handle build without tar

It seems this code does not consider that you might set
test-output-formats with only "qcow2" -- it currently also tries to
inspect a .tar output.

Skip if tar isn't in the output format list, and fall through to
passing so both paths are considered success, only exiting if there is
a failure.

Change-Id: Ia21dbfd298d04b04ec02dfe76a0acd7c9a7a31f2
---
 tests/run_functests.sh | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/tests/run_functests.sh b/tests/run_functests.sh
index 4aa7114fc..bcd179564 100755
--- a/tests/run_functests.sh
+++ b/tests/run_functests.sh
@@ -162,22 +162,25 @@ function run_disk_element_test() {
             fi
         fi
 
-        # check inside the tar for sentinel files
-        if ! [ -f "$dest_dir/image.tar" ]; then
-            echo "Error: Build failed for element: $element, test-element: $test_element."
-            echo "No image $dest_dir/image.tar found!"
-            logfile_status "FAIL" "${logfile}"
-            exit 1
-        else
-            if tar -tf $dest_dir/image.tar | grep -q /tmp/dib-test-should-fail; then
-                echo "Error: Element: $element, test-element $test_element should have failed, but passed."
+        if [[ "tar" =~ "$output_format" ]]; then
+            # check inside the tar for sentinel files
+            if ! [ -f "$dest_dir/image.tar" ]; then
+                echo "Error: Build failed for element: $element, test-element: $test_element."
+                echo "No image $dest_dir/image.tar found!"
                 logfile_status "FAIL" "${logfile}"
                 exit 1
             else
-                echo "PASS: Element $element, test-element: $test_element"
-                logfile_status "PASS" "${logfile}"
+                if tar -tf $dest_dir/image.tar | grep -q /tmp/dib-test-should-fail; then
+                    echo "Error: Element: $element, test-element $test_element should have failed, but passed."
+                    logfile_status "FAIL" "${logfile}"
+                    exit 1
+                fi
             fi
         fi
+
+        # if we got here, the test passed
+        echo "PASS: Element $element, test-element: $test_element"
+        logfile_status "PASS" "${logfile}"
     else
         if [ -f "${dest_dir}/dib-test-should-fail" ]; then
             echo "PASS: Element $element, test-element: $test_element"