aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/tests/misc/configsystem.cpp
blob: 0701204a16ea1874eee772f5d4aeb39b97020568 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/config/common/configsystem.h>
#include <vespa/defaults.h>
#include <vespa/fastos/file.h>
#include <unistd.h>
#include <filesystem>

using namespace config;

namespace {

const char *VESPA_HOME="VESPA_HOME";

}

TEST("require that bad home directory fails") {
    ASSERT_EQUAL(0, setenv(VESPA_HOME, "/nowhere/near/", 1));
    vespa::Defaults::bootstrap("/nowhere/near/");
    ConfigSystem configSystem;
    ASSERT_FALSE(configSystem.isUp());
}

TEST("require that incorrect pid file type fails") {
    std::string cwd = std::filesystem::current_path().string();
    std::filesystem::remove_all(std::filesystem::path("var"));
    std::filesystem::create_directories(std::filesystem::path("var/run/configproxy.pid"));

    ASSERT_EQUAL(0, setenv(VESPA_HOME, cwd.c_str(), 1));
    vespa::Defaults::bootstrap(cwd.c_str());
    ConfigSystem configSystem;
    ASSERT_FALSE(configSystem.isUp());
    std::filesystem::remove_all(std::filesystem::path("var"));
}

TEST("require that correct pid file succeeds") {
    std::string cwd = std::filesystem::current_path().string();
    std::filesystem::remove_all(std::filesystem::path("var"));
    std::filesystem::create_directories(std::filesystem::path("var/run"));
    FastOS_File pid_file("var/run/configproxy.pid");
    pid_file.OpenWriteOnlyTruncate();
    ASSERT_TRUE(pid_file.Close());

    ASSERT_EQUAL(0, setenv(VESPA_HOME, cwd.c_str(), 1));
    vespa::Defaults::bootstrap(cwd.c_str());
    ConfigSystem configSystem;
    ASSERT_TRUE(configSystem.isUp());
    std::filesystem::remove_all(std::filesystem::path("var"));
}

TEST_MAIN() { TEST_RUN_ALL(); }