]> granicus.if.org Git - vnstat/commitdiff
add more complex processdatacache() test
authorTeemu Toivola <git@humdi.net>
Sat, 17 Mar 2018 15:48:35 +0000 (17:48 +0200)
committerTeemu Toivola <git@humdi.net>
Sat, 17 Mar 2018 15:48:35 +0000 (17:48 +0200)
src/daemon.c
tests/daemon_tests.c
tests/database_tests.c

index 4233aa79ce0bf519fcd3ba9bd3475700a32b106d..0ac8c5828d276632d21a662dab4b2051c711a5af 100644 (file)
@@ -421,7 +421,6 @@ void checkdbsaveneed(DSTATE *s)
        }
 }
 
-/* TODO: tests */
 void processdatacache(DSTATE *s)
 {
        datacache *iterator = s->dcache;
@@ -474,6 +473,7 @@ void processdatacache(DSTATE *s)
                        db_removeoldentries();
                        s->cleanuphour = getcurrenthour();
                }
+               s->dodbsave = 0;
        }
 }
 
index 74b40b8ee6dbb2c2e2c10e82c50bb7ebd3ef3bd5..5bcd4d4aa989bb6020cfc5105c831b9f2d740ac3 100644 (file)
@@ -457,6 +457,56 @@ START_TEST(processdatacache_empty_does_nothing)
 }
 END_TEST
 
+START_TEST(processdatacache_can_process_things)
+{
+       /* ifinfo needs to be faked and that's currently
+          supported only in Linux */
+       linuxonly;
+
+       int ret;
+       DSTATE s;
+       defaultcfg();
+       initdstate(&s);
+       suppress_output();
+
+       ck_assert_int_eq(remove_directory(TESTDIR), 1);
+       debug = 1;
+
+       s.iflisthash = 42;
+       s.bootdetected = 1;
+       s.dodbsave = 1;
+       s.cleanuphour = getcurrenthour() + 1;
+
+       ck_assert_int_eq(datacache_count(&s.dcache), 0);
+       ret = datacache_add(&s.dcache, "ethnotindb", 0);
+       ck_assert_int_eq(ret, 1);
+       ret = datacache_add(&s.dcache, "ethonlyindb", 0);
+       ck_assert_int_eq(ret, 1);
+       ret = datacache_add(&s.dcache, "ethexisting", 0);
+       ck_assert_int_eq(ret, 1);
+       ck_assert_int_eq(datacache_count(&s.dcache), 3);
+
+       ret = db_open_rw(1);
+       ck_assert_int_eq(ret, 1);
+       ret = db_addinterface("ethonlyindb");
+       ck_assert_int_eq(ret, 1);
+       ret = db_addinterface("ethexisting");
+       ck_assert_int_eq(ret, 1);
+
+       fake_proc_net_dev("w", "ethexisting", 10, 20, 30, 40);
+
+       processdatacache(&s);
+
+       ck_assert_int_eq(s.iflisthash, 0);
+       ck_assert_int_eq(s.bootdetected, 0);
+       ck_assert_int_eq(s.dodbsave, 0);
+       ck_assert_int_eq(datacache_count(&s.dcache), 1);
+
+       ret = db_close();
+       ck_assert_int_eq(ret, 1);
+}
+END_TEST
+
 START_TEST(handleintsignals_handles_no_signal)
 {
        DSTATE s;
@@ -1112,6 +1162,7 @@ void add_daemon_tests(Suite *s)
        tcase_add_test(tc_daemon, checkdbsaveneed_is_forced);
        tcase_add_test(tc_daemon, checkdbsaveneed_needs);
        tcase_add_test(tc_daemon, processdatacache_empty_does_nothing);
+       tcase_add_test(tc_daemon, processdatacache_can_process_things);
        tcase_add_test(tc_daemon, handleintsignals_handles_no_signal);
        tcase_add_test(tc_daemon, handleintsignals_handles_42);
        tcase_add_test(tc_daemon, handleintsignals_handles_unknown_signal);
index 59be17f96cb28d2ec01b5ee545b4981a0b027b39..e7b2474bea0b799dced1f91cb0ce4a85c42a1f6f 100644 (file)
@@ -250,6 +250,9 @@ START_TEST(database_outputs_do_not_crash)
        showjson("something", 0, 'h');
        showjson("something", 0, 'a');
        jsonfooter();
+
+       ret = db_close();
+       ck_assert_int_eq(ret, 1);
 }
 END_TEST
 
@@ -298,6 +301,9 @@ START_TEST(database_outputs_do_not_crash_without_data)
        showjson("something", 0, 'h');
        showjson("something", 0, 'a');
        jsonfooter();
+
+       ret = db_close();
+       ck_assert_int_eq(ret, 1);
 }
 END_TEST