]> source.dussan.org Git - rspamd.git/commitdiff
Fix tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 20 Nov 2015 16:33:34 +0000 (16:33 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 20 Nov 2015 16:33:34 +0000 (16:33 +0000)
test/lua/unit/redis_stat.lua
test/rspamd_test_suite.c
test/rspamd_upstream_test.c

index f994bdf010ec182e9017626d259c2d784a0f89b2..f4e02f5efe9974dc9a0a4535a8ba14da722f472d 100644 (file)
@@ -1,8 +1,9 @@
 
-    
+
 context("Redis statistics unit tests", function()
   local task = require("rspamd_task")
   local ffi = require("ffi")
+  local rspamd_util = require("rspamd_util")
   ffi.cdef[[
   struct rspamd_statfile_config {
     const char *symbol;
@@ -16,7 +17,7 @@ context("Redis statistics unit tests", function()
     struct rspamd_statfile_config *stcf,
     struct rspamd_task *task,
     char **target);
-  struct rspamd_task * rspamd_task_new(struct rspamd_worker *worker);
+  struct rspamd_task * rspamd_task_new(struct rspamd_worker *worker, struct rspamd_config *cfg);
   int rspamd_task_add_recipient (struct rspamd_task *task, const char *rcpt);
   int rspamd_task_add_sender (struct rspamd_task *task, const char *sender);
   ]]
@@ -30,14 +31,36 @@ context("Redis statistics unit tests", function()
       {"%r%l", "test@example.comlabel"},
       {"%f-from", "test@example.com-from"}
     }
-    local stcf = ffi.new("struct rspamd_statfile_config", 
+    local config = {
+      options = {
+        filters = { 'spf', 'dkim', 'regexp' },
+        url_tld = tld_file,
+        dns = {
+          nameserver = { '8.8.8.8' }
+        },
+      },
+      logging = {
+        type = 'console',
+        level = 'debug'
+      },
+      metric = {
+        name = 'default',
+        actions = {
+          reject = 100500,
+        },
+        unknown_weight = 1
+      }
+    }
+    local cfg = rspamd_util.config_from_ucl(config)
+    assert_not_nil(cfg)
+    local stcf = ffi.new("struct rspamd_statfile_config",
       {symbol="symbol",label="label"})
-    local t = ffi.C.rspamd_task_new(nil)
-    
+    local t = ffi.C.rspamd_task_new(nil, cfg)
+
     assert_equal(ffi.C.rspamd_task_add_recipient(t, "Test <test@example.com>"), 1)
     assert_equal(ffi.C.rspamd_task_add_recipient(t, "Test1 <test1@example.com>"), 1)
     assert_equal(ffi.C.rspamd_task_add_sender(t, "Test <test@example.com>"), 1)
-    
+
     for _,c in ipairs(cases) do
       local pbuf = ffi.new 'char *[1]'
       local sz = ffi.C.rspamd_redis_expand_object(c[1], stcf, t, pbuf)
@@ -45,4 +68,4 @@ context("Redis statistics unit tests", function()
       assert_equal(s, c[2])
     end
   end)
-end)
\ No newline at end of file
+end)
index 97d0565b80e7348aebb87f264a849b1c805f30bb..4ba11ea0fa4cf28b9db6c1332c9dbaddf08a8fcd 100644 (file)
@@ -16,10 +16,8 @@ main (int argc, char **argv)
        rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
        memset (rspamd_main, 0, sizeof (struct rspamd_main));
        rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
-       rspamd_main->cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
-       cfg = rspamd_main->cfg;
-       memset (cfg, 0, sizeof (struct rspamd_config));
-       rspamd_init_cfg (cfg, FALSE);
+       cfg = rspamd_config_new ();
+       rspamd_main->cfg = cfg;
        cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
        cfg->log_type = RSPAMD_LOG_CONSOLE;
        cfg->log_level = G_LOG_LEVEL_INFO;
@@ -29,7 +27,7 @@ main (int argc, char **argv)
 
        g_test_init (&argc, &argv, NULL);
 
-       rspamd_init_libs ();
+       cfg->libs_ctx = rspamd_init_libs ();
        rspamd_stat_init (cfg);
 
        base = event_init ();
index 528b0a9dcd66647a5382b087605e7062d5a1add4..0cf163322648aefc9c632992a568fece69c1e41a 100644 (file)
@@ -85,10 +85,10 @@ rspamd_upstream_test_func (void)
 
        resolver = dns_resolver_init (NULL, ev_base, cfg);
 
-       rspamd_upstreams_library_init (resolver->r, ev_base);
-       rspamd_upstreams_library_config (cfg);
+       cfg->ups_ctx = rspamd_upstreams_library_init (resolver->r, ev_base);
+       rspamd_upstreams_library_config (cfg, cfg->ups_ctx);
 
-       ls = rspamd_upstreams_create ();
+       ls = rspamd_upstreams_create (cfg->ups_ctx);
        g_assert (rspamd_upstreams_parse_line (ls, test_upstream_list, 443, NULL));
        g_assert (rspamd_upstreams_count (ls) == 3);
 
@@ -105,7 +105,7 @@ rspamd_upstream_test_func (void)
        rspamd_upstream_test_method (ls, RSPAMD_UPSTREAM_ROUND_ROBIN, "microsoft.com");
 
        /* Test stable hashing */
-       nls = rspamd_upstreams_create ();
+       nls = rspamd_upstreams_create (cfg->ups_ctx);
        g_assert (rspamd_upstreams_parse_line (nls, test_upstream_list, 443, NULL));
        g_assert (rspamd_upstreams_parse_line (nls, new_upstream_list, 443, NULL));
        for (i = 0; i < assumptions; i ++) {
@@ -135,7 +135,7 @@ rspamd_upstream_test_func (void)
        /*
         * Test v4/v6 priorities
         */
-       nls = rspamd_upstreams_create ();
+       nls = rspamd_upstreams_create (cfg->ups_ctx);
        g_assert (rspamd_upstreams_add_upstream (nls, "127.0.0.1", 0, NULL));
        up = rspamd_upstream_get (nls, RSPAMD_UPSTREAM_RANDOM);
        rspamd_parse_inet_address (&paddr, "127.0.0.2", 0);
@@ -169,6 +169,5 @@ rspamd_upstream_test_func (void)
        event_base_loop (ev_base, 0);
        g_assert (rspamd_upstreams_alive (ls) == 3);
 
-       g_free (cfg);
        rspamd_upstreams_destroy (ls);
 }