test-bus-unit-util: use an unconnected bus instead of connecting

The test only constructs messages locally and never sends them, so a real
connection is not needed. Create the bus with sd_bus_new() and fake the state,
like test-bus-util does, so that the test is never skipped when no bus is
available.

(cherry picked from commit 970993efbebb6a302417b593a3935f28bab7c192)
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-10-16 17:24:52 +01:00
committed by Luca Boccassi
parent 2d3dd0a4fc
commit ad0dde105c
+4 -10
View File
@@ -2,6 +2,7 @@
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-unit-util.h"
#include "extract-word.h"
#include "unit-def.h"
@@ -15,9 +16,6 @@ static void test_transient_settings_one(UnitType type, const char* const* lines)
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
if (!arg_bus)
return (void) log_tests_skipped("no bus connection");
ASSERT_OK(sd_bus_message_new(arg_bus, &m, SD_BUS_MESSAGE_METHOD_CALL));
STRV_FOREACH(s, lines) {
@@ -1167,13 +1165,9 @@ TEST(bus_dump_transient_settings) {
}
static int intro(void) {
int r;
r = sd_bus_default_user(&arg_bus);
if (r < 0)
r = sd_bus_default_system(&arg_bus);
if (r < 0)
log_info_errno(r, "Failed to connect to bus: %m");
/* An unconnected bus is sufficient to construct and inspect messages locally. */
ASSERT_OK(sd_bus_new(&arg_bus));
arg_bus->state = BUS_RUNNING; /* Fake state to allow message creation */
return EXIT_SUCCESS;
}