commit 1727d1d: [Test] Properly set test cases

Vsevolod Stakhov vsevolod at rspamd.com
Fri Apr 15 21:14:06 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-04-15 21:42:39 +0100
URL: https://github.com/rspamd/rspamd/commit/1727d1df984ffadaa696d5057e54635f25304fd5

[Test] Properly set test cases

---
 test/rspamd_cxx_unit_dkim.hxx | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/test/rspamd_cxx_unit_dkim.hxx b/test/rspamd_cxx_unit_dkim.hxx
index 802e9ecbf..79556a58e 100644
--- a/test/rspamd_cxx_unit_dkim.hxx
+++ b/test/rspamd_cxx_unit_dkim.hxx
@@ -21,7 +21,7 @@
 
 #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
 #include "doctest/doctest.h"
-
+#include "fmt/core.h"
 #include "libserver/dkim.h"
 
 #include <vector>
@@ -142,23 +142,23 @@ TEST_CASE("rspamd_dkim_parse_key")
 			 false, ""},
 	};
 
+	auto cur_test_idx = 0;
 	for (auto &&c : cases) {
-		SUBCASE (("process DKIM record " + c.input).c_str()) {
+		SUBCASE (fmt::format("process DKIM record {}: {}", cur_test_idx++, c.input).c_str()) {
+			GError *err = nullptr;
 			gsize klen = c.input.size();
-			auto *key = rspamd_dkim_parse_key(c.input.c_str(), &klen, nullptr);
+			auto *key = rspamd_dkim_parse_key(c.input.c_str(), &klen, &err);
 			if (c.is_valid) {
-				CHECK(key != nullptr);
+				REQUIRE_MESSAGE(key != nullptr, (err ? err->message : "unknown error"));
 				char hexbuf[RSPAMD_DKIM_KEY_ID_LEN * 2 + 1];
 				auto *id = rspamd_dkim_key_id(key);
-				CHECK(id != nullptr);
+				REQUIRE(id != nullptr);
 
-				if (id) {
-					auto hexlen = rspamd_encode_hex_buf(id, RSPAMD_DKIM_KEY_ID_LEN, hexbuf,
-							sizeof(hexbuf));
-					CHECK(hexlen > 0);
-					CHECK(std::string{hexbuf, (std::size_t) hexlen} == c.expected_id);
-					rspamd_dkim_key_free(key);
-				}
+				auto hexlen = rspamd_encode_hex_buf(id, RSPAMD_DKIM_KEY_ID_LEN, hexbuf,
+						sizeof(hexbuf));
+				CHECK(hexlen > 0);
+				CHECK(std::string{hexbuf, (std::size_t) hexlen} == c.expected_id);
+				rspamd_dkim_key_free(key);
 			}
 			else {
 				CHECK(key == nullptr);


More information about the Commits mailing list