File: tests-engine.cpp

package info (click to toggle)
appstream-generator 0.10.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,344 kB
  • sloc: cpp: 42,038; python: 292; xml: 259; sh: 223; makefile: 20
file content (79 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2019-2025 Matthias Klumpp <matthias@tenstral.net>
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#define CATCH_CONFIG_MAIN
#include <catch2/catch_all.hpp>

#include <filesystem>
#include <string>

#include "logging.h"
#include "utils.h"
#include "config.h"
#include "engine.h"

using namespace ASGenerator;

static struct TestSetup {
    TestSetup()
    {
        setVerbose(true);
    }
} testSetup;

TEST_CASE("Engine with test data", "[engine][integration]")
{
    auto tempDir = fs::temp_directory_path() / std::format("asgen-test-{}", Utils::randomString(8));
    fs::create_directories(tempDir);
    auto samplesDir = Utils::getTestSamplesDir();

    SECTION("Test init with Debian backend")
    {
        auto debianSamplesDir = samplesDir / "debian";

        auto &config = Config::get();
        config.setWorkspaceDir("/tmp");
        config.backend = Backend::Debian;
        config.archiveRoot = debianSamplesDir.string();

        REQUIRE_NOTHROW([]() {
            Engine engine;
        }());
    }

    fs::remove_all(tempDir);
}

TEST_CASE("Engine package info functionality", "[engine]")
{
    auto tempDir = fs::temp_directory_path() / std::format("asgen-test-{}", Utils::randomString(8));
    fs::create_directories(tempDir);

    auto &config = Config::get();
    config.backend = Backend::Dummy;
    config.setWorkspaceDir("/tmp");
    config.archiveRoot = (Utils::getTestSamplesDir() / "debian").string();

    Engine engine;

    SECTION("Print package info with invalid ID format")
    {
        // Test with malformed package ID (should return false)
        REQUIRE_FALSE(engine.printPackageInfo("invalid-package-id"));
        REQUIRE_FALSE(engine.printPackageInfo("too/many/slashes/here"));
        REQUIRE_FALSE(engine.printPackageInfo("notEnoughSlashes"));
    }

    SECTION("Print package info with valid ID format")
    {
        // Test with properly formatted package ID (even if package doesn't exist)
        // This should return true as the format is correct, even if no data is found
        REQUIRE(engine.printPackageInfo("package/1.0.0/amd64"));
        REQUIRE(engine.printPackageInfo("test-pkg/2.1.0/i386"));
    }

    fs::remove_all(tempDir);
}