@cryptotaxi247 / netdata-1 / commits / f541feb7f

Simple SQLite unit tests (#11422)

Stelios Fragkakis committed Aug 12, 2021 at 18:30 UTC f541feb7f0df5b6159ea6176eb6577a485a15b71
3 files changed +34
daemon/main.c
+1
@@ -823,6 +823,7 @@ int main(int argc, char **argv) {
823 #ifdef ENABLE_DBENGINE
824 if(test_dbengine()) return 1;
825 #endif
826 + if(test_sqlite()) return 1;
827 fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
828 return 0;
829 }
daemon/unit_test.c
+32
@@ -1475,6 +1475,38 @@ int unit_test(long delay, long shift)
1475 return ret;
1476 }
1477
1478 +int test_sqlite(void) {
1479 + sqlite3 *db_meta;
1480 + fprintf(stderr, "Testing SQLIte\n");
1481 +
1482 + int rc = sqlite3_open(":memory:", &db_meta);
1483 + if (rc != SQLITE_OK) {
1484 + fprintf(stderr,"Failed to test SQLite: DB init failed\n");
1485 + return 1;
1486 + }
1487 +
1488 + rc = sqlite3_exec(db_meta, "CREATE TABLE IF NOT EXISTS mine (id1, id2);", 0, 0, NULL);
1489 + if (rc != SQLITE_OK) {
1490 + fprintf(stderr,"Failed to test SQLite: Create table failed\n");
1491 + return 1;
1492 + }
1493 +
1494 + rc = sqlite3_exec(db_meta, "DELETE FROM MINE LIMIT 1;", 0, 0, NULL);
1495 + if (rc != SQLITE_OK) {
1496 + fprintf(stderr,"Failed to test SQLite: Delete with LIMIT failed\n");
1497 + return 1;
1498 + }
1499 +
1500 + rc = sqlite3_exec(db_meta, "UPDATE MINE SET id1=1 LIMIT 1;", 0, 0, NULL);
1501 + if (rc != SQLITE_OK) {
1502 + fprintf(stderr,"Failed to test SQLite: Update with LIMIT failed\n");
1503 + return 1;
1504 + }
1505 + fprintf(stderr,"SQLite is OK\n");
1506 + return 0;
1507 +}
1508 +
1509 +
1510 #ifdef ENABLE_DBENGINE
1511 static inline void rrddim_set_by_pointer_fake_time(RRDDIM *rd, collected_number value, time_t now)
1512 {
daemon/unit_test.h
+1
@@ -8,6 +8,7 @@ extern int unit_test(long delay, long shift);
8 extern int run_all_mockup_tests(void);
9 extern int unit_test_str2ld(void);
10 extern int unit_test_buffer(void);
11 +extern int test_sqlite(void);
12 #ifdef ENABLE_DBENGINE
13 extern int test_dbengine(void);
14 extern void generate_dbengine_dataset(unsigned history_seconds);