Skip to content

Commit

Permalink
Set assertion error message as message attr in <failure>
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahFrench committed Jan 13, 2025
1 parent 53b7636 commit 1c3b128
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/command/junit/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c3b128

Please sign in to comment.