Blob Blame History Raw
From 9a90a05c9000dc7d21afcfab6efbd26715aa3f08 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Mon, 8 Jun 2015 11:32:23 +0200
Subject: [PATCH] testsuite: add a test for AlwaysExcludedElements

Related: #362

Signed-off-by: Jakub Filak <jfilak@redhat.com>

Conflicts:
	tests/Makefile.am
---
 tests/Makefile.am      |   3 +-
 tests/global_config.at | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/testsuite.at     |   1 +
 3 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 tests/global_config.at

diff --git a/tests/Makefile.am b/tests/Makefile.am
index eaf1ac2..5ed7af6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,7 +43,8 @@ TESTSUITE_AT = \
   xfuncs.at \
   string_list.at \
   ureport.at \
-  dump_dir.at
+  dump_dir.at \
+  global_config.at
 
 EXTRA_DIST += $(TESTSUITE_AT)
 TESTSUITE = $(srcdir)/testsuite
diff --git a/tests/global_config.at b/tests/global_config.at
new file mode 100644
index 0000000..a6f5423
--- /dev/null
+++ b/tests/global_config.at
@@ -0,0 +1,104 @@
+# -*- Autotest -*-
+
+AT_BANNER([global_config])
+
+## ------------------------ ##
+## always_excluded_elements ##
+## ------------------------ ##
+
+AT_TESTFUN([always_excluded_elements],
+[[
+#include "internal_libreport.h"
+#include <errno.h>
+#include <assert.h>
+
+int main(int argc, char **argv)
+{
+    g_verbose = 3;
+    char cwd_buf[PATH_MAX + 1];
+
+    static const char *dirs[] = {
+        NULL,
+        NULL,
+    };
+    dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf));
+
+    static int dir_flags[] = {
+        CONF_DIR_FLAG_NONE,
+        -1,
+    };
+
+    unlink("libreport.conf");
+    FILE *lrf = fopen("libreport.conf", "wx");
+    assert(lrf != NULL);
+    fclose(lrf);
+
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
+
+    {
+        unsetenv("EXCLUDE_FROM_REPORT");
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
+
+        assert(excluded != NULL);
+        assert(excluded[0] == NULL);
+
+        string_vector_free(excluded);
+    }
+
+    {
+        setenv("EXCLUDE_FROM_REPORT", "hostname, environ, uid", 1);
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
+
+        assert(excluded != NULL);
+        assert(strcmp(excluded[0], "hostname") == 0);
+        assert(strcmp(excluded[1], "environ") == 0);
+        assert(strcmp(excluded[2], "uid") == 0);
+        assert(excluded[3] == NULL);
+
+        string_vector_free(excluded);
+    }
+
+    free_global_configuration();
+
+    unlink("libreport.conf");
+    lrf = fopen("libreport.conf", "wx");
+    assert(lrf != NULL);
+    fprintf(lrf, "AlwaysExcludedElements = maps, var_log_messages, proc_pid_status");
+    fclose(lrf);
+
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
+
+    {
+        unsetenv("EXCLUDE_FROM_REPORT");
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
+
+        assert(excluded != NULL);
+        assert(strcmp(excluded[0], "maps") == 0);
+        assert(strcmp(excluded[1], "var_log_messages") == 0);
+        assert(strcmp(excluded[2], "proc_pid_status") == 0);
+        assert(excluded[3] == NULL);
+
+        string_vector_free(excluded);
+    }
+
+    {
+        setenv("EXCLUDE_FROM_REPORT", "hostname, environ, uid", 1);
+        string_vector_ptr_t excluded = get_global_always_excluded_elements();
+
+        assert(excluded != NULL);
+        assert(strcmp(excluded[0], "hostname") == 0);
+        assert(strcmp(excluded[1], "environ") == 0);
+        assert(strcmp(excluded[2], "uid") == 0);
+        assert(strcmp(excluded[3], "maps") == 0);
+        assert(strcmp(excluded[4], "var_log_messages") == 0);
+        assert(strcmp(excluded[5], "proc_pid_status") == 0);
+        assert(excluded[6] == NULL);
+
+        string_vector_free(excluded);
+    }
+
+    unlink("libreport.conf");
+
+    return EXIT_SUCCESS;
+}
+]])
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 41107e7..91f0823 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -18,3 +18,4 @@ m4_include([report_python.at])
 m4_include([string_list.at])
 m4_include([ureport.at])
 m4_include([dump_dir.at])
+m4_include([global_config.at])
-- 
1.8.3.1