From 1c3b1283b99898e7f244b21753b105c8aaf1c68c Mon Sep 17 00:00:00 2001 From: Sarah French Date: Mon, 13 Jan 2025 20:22:58 +0000 Subject: [PATCH] Set assertion error message as message attr in --- internal/command/junit/junit.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/command/junit/junit.go b/internal/command/junit/junit.go index 39145dd63b7a..7e5a4310657d 100644 --- a/internal/command/junit/junit.go +++ b/internal/command/junit/junit.go @@ -239,8 +239,9 @@ func junitXMLTestReport(suite *moduletest.Suite, suiteRunnerStopped bool, source delete(diagsMap, key) } } + msg := getFailMessage(diagsStr.String()) testCase.Failure = &withMessage{ - Message: "Test run failed", + Message: msg, Body: diagsStr.String(), } case moduletest.Error: @@ -281,6 +282,17 @@ func junitXMLTestReport(suite *moduletest.Suite, suiteRunnerStopped bool, source return buf.Bytes(), nil } +func getFailMessage(diagsStr string) string { + diagLines := strings.Split(diagsStr, "\n") + for i := len(diagLines) - 1; i >= 0; i-- { + if diagLines[i] != "" { + return diagLines[i] + } + } + + return "" +} + // getSkipDetails checks data about the test suite, file and runs to determine why a given run was skipped // Test can be skipped due to: // 1. terraform test recieving an interrupt from users; all unstarted tests will be skipped