Debian Codegraph @

tests/conf.cpp

raw
1 /*
2 * Copyright © 2018 Simon Désaulniers
3 * Author: Simon Désaulniers <[email protected]>
4 *
5 * This file is part of dpaste.
6 *
7 * dpaste is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * dpaste is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with dpaste. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <catch.hpp>
22
23 #include "conf.h"
24
25 namespace dpaste {
26 namespace tests {
27
28 const std::string CONFIG_FILE_PATH_PREFIX = "./tests/misc/dpaste.conf";
29
30 TEST_CASE("ConfigurationFile loading/parsing (./misc/dpaste.conf)", "[ConfigurationFile][get][load]") {
31 SECTION ( "Well-formed file" ) {
32 conf::ConfigurationFile f(CONFIG_FILE_PATH_PREFIX+".1");
33 REQUIRE ( f.load() == 0 );
34
35 auto c = f.getConfiguration();
36 REQUIRE ( c.at("host") == "192.168.1.100" );
37 REQUIRE ( c.at("port") == "6500" );
38 }
39 SECTION ( "Malformed file (bad host)" ) {
40 conf::ConfigurationFile f(CONFIG_FILE_PATH_PREFIX+".2");
41 REQUIRE ( f.load() == 0 );
42
43 auto c = f.getConfiguration();
44 REQUIRE ( c.at("host") == "127.0.0.1" ); /* the default */
45 REQUIRE ( c.at("port") == "6500" ); /* recovered from file */
46 }
47 SECTION ( "File not found" ) {
48 conf::ConfigurationFile f("/dpaste.conf"); /* This should not work on
49 any computer owned by a
50 sane person */
51 REQUIRE ( f.load() == 1 );
52 }
53 }
54
55 } /* tests */
56 } /* dpaste */
57
58 /* vim: set ts=4 sw=4 tw=120 et :*/
59