summaryrefslogtreecommitdiffstats
path: root/config/src/tests/misc/configsystem.cpp
blob: f0f526265caa6952cd03b38a99beff572dcd1e01 (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 2017 Yahoo Holdings. 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/config/common/configsystem.h>
#include <vespa/defaults.h>
#include <vespa/fastos/file.h>

using namespace config;

namespace {

const char *VESPA_HOME="VESPA_HOME";
char cwd[1024];

}

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();
    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(); }