void test_journald_helper() { Journald *journald = journald_mock_new(); journald_open(journald, 0); MockEntry *entry = mock_entry_new("test_data1"); mock_entry_add_data(entry, "MESSAGE=test message"); mock_entry_add_data(entry, "KEY=VALUE"); mock_entry_add_data(entry, "HOST=testhost"); journald_mock_add_entry(journald, entry); journald_seek_head(journald); journald_next(journald); GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); journald_foreach_data(journald, __helper_test, result); gchar *message = g_hash_table_lookup(result, "MESSAGE"); gchar *key = g_hash_table_lookup(result, "KEY"); gchar *host = g_hash_table_lookup(result, "HOST"); assert_string(message, "test message", ASSERTION_ERROR("Bad item")); assert_string(key, "VALUE", ASSERTION_ERROR("Bad item")); assert_string(host, "testhost", ASSERTION_ERROR("Bad item")); journald_close(journald); journald_free(journald); g_hash_table_unref(result); }
Test(systemd_journal, test_journald_helper) { const gchar *persist_file = "test_systemd_journal2.persist"; _init_cfg_with_persist_file(persist_file); Journald *journald = journald_mock_new(); journald_open(journald, 0); MockEntry *entry = mock_entry_new("test_data1"); mock_entry_add_data(entry, "MESSAGE=test message"); mock_entry_add_data(entry, "KEY=VALUE"); mock_entry_add_data(entry, "HOST=testhost"); journald_mock_add_entry(journald, entry); journald_seek_head(journald); journald_next(journald); GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); journald_foreach_data(journald, __helper_test, result); gchar *message = g_hash_table_lookup(result, "MESSAGE"); gchar *key = g_hash_table_lookup(result, "KEY"); gchar *host = g_hash_table_lookup(result, "HOST"); cr_assert_str_eq(message, "test message", "%s", "Bad item"); cr_assert_str_eq(key, "VALUE", "%s", "Bad item"); cr_assert_str_eq(host, "testhost", "%s", "Bad item"); journald_close(journald); journald_free(journald); g_hash_table_unref(result); _deinit_cfg(persist_file); }
static gboolean __handle_message(JournalReader *self) { LogMessage *msg = log_msg_new_empty(); msg->pri = self->options->default_pri; gpointer args[] = {msg, self->options}; journald_foreach_data(self->journal, __handle_data, args); __set_message_timestamp(self, msg); log_source_post(&self->super, msg); return log_source_free_to_send(&self->super); }