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 57 58 59
|
/*
* Copyright © 2018 Simon Désaulniers
* Author: Simon Désaulniers <sim.desaulniers@gmail.com>
*
* This file is part of dpaste.
*
* dpaste is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dpaste is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dpaste. If not, see <http://www.gnu.org/licenses/>.
*/
#include <catch.hpp>
#include "conf.h"
namespace dpaste {
namespace tests {
const std::string CONFIG_FILE_PATH_PREFIX = "./tests/misc/dpaste.conf";
TEST_CASE("ConfigurationFile loading/parsing (./misc/dpaste.conf)", "[ConfigurationFile][get][load]") {
SECTION ( "Well-formed file" ) {
conf::ConfigurationFile f(CONFIG_FILE_PATH_PREFIX+".1");
REQUIRE ( f.load() == 0 );
auto c = f.getConfiguration();
REQUIRE ( c.at("host") == "192.168.1.100" );
REQUIRE ( c.at("port") == "6500" );
}
SECTION ( "Malformed file (bad host)" ) {
conf::ConfigurationFile f(CONFIG_FILE_PATH_PREFIX+".2");
REQUIRE ( f.load() == 0 );
auto c = f.getConfiguration();
REQUIRE ( c.at("host") == "127.0.0.1" ); /* the default */
REQUIRE ( c.at("port") == "6500" ); /* recovered from file */
}
SECTION ( "File not found" ) {
conf::ConfigurationFile f("/dpaste.conf"); /* This should not work on
any computer owned by a
sane person */
REQUIRE ( f.load() == 1 );
}
}
} /* tests */
} /* dpaste */
/* vim: set ts=4 sw=4 tw=120 et :*/
|