blob: db6764e6b17a2f7b41f49dcfdbb73ac8ceea67b9 (
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
53
54
|
// Copyright Yahoo. 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";
char cwd[1_Ki];
}
TEST("require that bad home directory fails") {
ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd)));
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") {
ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd)));
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, 1));
vespa::Defaults::bootstrap(cwd);
ConfigSystem configSystem;
ASSERT_FALSE(configSystem.isUp());
std::filesystem::remove_all(std::filesystem::path("var"));
}
TEST("require that correct pid file succeeds") {
ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd)));
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, 1));
vespa::Defaults::bootstrap(cwd);
ConfigSystem configSystem;
ASSERT_TRUE(configSystem.isUp());
std::filesystem::remove_all(std::filesystem::path("var"));
}
TEST_MAIN() { TEST_RUN_ALL(); }
|