1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2024-09-28 14:30:45 +00:00
ohwgiles_laminar/test/unit-conf.cpp
Oliver Giles 39ca7e86cf replace websockets with sse and refactor
Large refactor that more closely aligns the codebase to the kj async
style, more clearly exposes an interface for functional testing and
removes cruft. There is a slight increase in coupling between the
Laminar and Http/Rpc classes, but this was always an issue, just until
now more obscured by the arbitrary pure virtual LaminarInterface class
(which has been removed in this change) and the previous lumping
together of all the async stuff in the Server class (which is now
more spread around the code according to function).

This change replaces the use of Websockets with Server Side Events
(SSE). They are simpler and more suitable for the publish-style messages
used by Laminar, and typically require less configuration of the
reverse proxy HTTP server.

Use of gmock is also removed, which eases testing in certain envs.

Resolves #90.
2019-10-05 20:06:35 +03:00

64 lines
1.7 KiB
C++

///
/// Copyright 2018 Oliver Giles
///
/// This file is part of Laminar
///
/// Laminar 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.
///
/// Laminar 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 Laminar. If not, see <http://www.gnu.org/licenses/>
///
#include <gtest/gtest.h>
#include "conf.h"
class ConfTest : public ::testing::Test {
protected:
void SetUp() override {
fd = mkstemp(tmpFile);
}
void TearDown() override {
close(fd);
unlink(tmpFile);
}
void parseConf(std::string conf) {
lseek(fd, SEEK_SET, 0);
write(fd, conf.data(), conf.size());
cfg = parseConfFile(tmpFile);
}
StringMap cfg;
int fd;
char tmpFile[32] = "/tmp/lt.XXXXXX";
};
TEST_F(ConfTest, Empty) {
EXPECT_TRUE(cfg.empty());
parseConf("");
EXPECT_TRUE(cfg.empty());
}
TEST_F(ConfTest, Comments) {
parseConf("#");
EXPECT_TRUE(cfg.empty());
parseConf("#foo=bar");
EXPECT_TRUE(cfg.empty());
}
TEST_F(ConfTest, Parse) {
parseConf("foo=bar\nbar=3");
ASSERT_EQ(2, cfg.size());
EXPECT_EQ("bar", cfg.get("foo", std::string("fallback")));
EXPECT_EQ(3, cfg.get("bar", 0));
}
TEST_F(ConfTest, Fallback) {
EXPECT_EQ("foo", cfg.get("test", std::string("foo")));
}