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); }
void test_journald_mock() { Journald *journald = journald_mock_new(); gint result = journald_open(journald, 0); assert_gint(result, 0, ASSERTION_ERROR("Can't open journald mock")); __test_seeks(journald); __test_cursors(journald); __test_fd_handling(journald); journald_close(journald); journald_free(journald); }
TestSource * test_source_new(GlobalConfig *cfg) { TestSource *self = g_new0(TestSource, 1); log_pipe_init_instance(&self->super, cfg); self->super.init = __init; self->super.deinit = __deinit; self->super.free_fn = __free; self->super.queue = __queue; self->journald_mock = journald_mock_new(); journal_reader_options_defaults(&self->options); IV_TASK_INIT(&self->start); self->start.cookie = self; self->start.handler = __start_source; IV_TASK_INIT(&self->stop); self->stop.cookie = self; self->stop.handler = __stop_source; return self; }
Test(systemd_journal, test_journald_mock) { const gchar *persist_file = "test_systemd_journal3.persist"; _init_cfg_with_persist_file(persist_file); Journald *journald = journald_mock_new(); gint result = journald_open(journald, 0); cr_assert_eq(result, 0, "%s", "Can't open journald mock"); __test_seeks(journald); __test_cursors(journald); __test_fd_handling(journald); journald_close(journald); journald_free(journald); _deinit_cfg(persist_file); }