blob: db3d0a80706bc570b045f3146778efe74d5b787d (
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
55
56
|
// 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>
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)));
FastOS_File::EmptyAndRemoveDirectory("var");
FastOS_File::MakeDirIfNotPresentOrExit("var");
FastOS_File::MakeDirIfNotPresentOrExit("var/run");
FastOS_File::MakeDirIfNotPresentOrExit("var/run/configproxy.pid");
ASSERT_EQUAL(0, setenv(VESPA_HOME, cwd, 1));
vespa::Defaults::bootstrap(cwd);
ConfigSystem configSystem;
ASSERT_FALSE(configSystem.isUp());
FastOS_File::EmptyAndRemoveDirectory("var");
}
TEST("require that correct pid file succeeds") {
ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd)));
FastOS_File::EmptyAndRemoveDirectory("var");
FastOS_File::MakeDirIfNotPresentOrExit("var");
FastOS_File::MakeDirIfNotPresentOrExit("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());
FastOS_File::EmptyAndRemoveDirectory("var");
}
TEST_MAIN() { TEST_RUN_ALL(); }
|