~aleteoryx/muditaos

c42df2435d7c41c45f36f9da9f61442eb1326100 — Pawel.Paprocki 4 years ago 71465d8
[EGD-6646] Fix Contact Record db tests

Clean  WAL file after db init
M module-db/tests/CMakeLists.txt => module-db/tests/CMakeLists.txt +1 -0
@@ 32,6 32,7 @@ add_catch2_executable(
        ThreadRecord_tests.cpp
        ThreadsTable_tests.cpp
        tests-main.cpp
        common.cpp
        
    LIBS
        module-db

M module-db/tests/ContactsRecord_tests.cpp => module-db/tests/ContactsRecord_tests.cpp +3 -6
@@ 1,6 1,7 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "common.hpp"
#include <catch2/catch.hpp>

#include "Interface/ContactRecord.hpp"


@@ 12,9 13,7 @@ TEST_CASE("Contact Record db tests")
    Database::initialize();

    const auto contactsPath = (std::filesystem::path{"sys/user"} / "contacts.db");
    if (std::filesystem::exists(contactsPath)) {
        REQUIRE(std::filesystem::remove(contactsPath));
    }
    RemoveDbFiles(contactsPath.stem());

    ContactsDB contactDB(contactsPath.c_str());
    REQUIRE(contactDB.isInitialized());


@@ 263,9 262,7 @@ TEST_CASE("Contact record numbers update")
{
    Database::initialize();
    const auto contactsPath = (std::filesystem::path{"sys/user"} / "contacts.db");
    if (std::filesystem::exists(contactsPath)) {
        REQUIRE(std::filesystem::remove(contactsPath));
    }
    RemoveDbFiles(contactsPath.stem());

    ContactsDB contactDB(contactsPath.c_str());
    REQUIRE(contactDB.isInitialized());

A module-db/tests/common.cpp => module-db/tests/common.cpp +16 -0
@@ 0,0 1,16 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "common.hpp"
#include <vector>
#include <filesystem>

void RemoveDbFiles(const std::string &dbName)
{
    std::vector<std::string> dbFileExt = {".db", ".db-journal", ".db-wal"};
    for (const auto &ext : dbFileExt) {
        const auto dbPath = (std::filesystem::path{"sys/user"} / std::filesystem::path{dbName + ext});
        if (std::filesystem::exists(dbPath)) {
            std::filesystem::remove(dbPath.c_str());
        }
    }
}

A module-db/tests/common.hpp => module-db/tests/common.hpp +8 -0
@@ 0,0 1,8 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <string>

void RemoveDbFiles(const std::string &dbName);