-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_parser_test.cc
86 lines (69 loc) · 2.04 KB
/
config_parser_test.cc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "gtest/gtest.h"
#include "config_parser.h"
TEST(NginxConfigTest, ToString){
NginxConfigStatement statement;
statement.tokens_.push_back("Statement with spaces");
statement.tokens_.push_back("1");
EXPECT_EQ(statement.ToString(0), "Statement with spaces 1;\n");
}
// Fixture to be used for testing the NginxConfigParser parse functions
class NginxConfigParserTest : public :: testing::Test {
protected:
NginxConfigParser parser_;
NginxConfig output_config_;
};
// Basic Config
TEST_F(NginxConfigParserTest, SimpleConfig) {
bool success = parser_.Parse("config", &output_config_);
EXPECT_TRUE(success);
}
// No File Config
TEST_F(NginxConfigParserTest, NotFoundConfig){
bool failure = parser_.Parse("no_config_here", &output_config_);
EXPECT_FALSE(failure);
}
// Nested Configuration
TEST_F(NginxConfigParserTest, NestedConfig){
std::string config_string =
"server {"
" location {"
" /home/;"
" }"
"}";
std::stringstream config_stream(config_string);
bool success = parser_.Parse(&config_stream, &output_config_);
EXPECT_TRUE(success);
}
// Bad Brackets
TEST_F(NginxConfigParserTest, IncorrectBracketConfig){
std::string bad_config =
"server {"
" /home/;"
"}}";
std::stringstream config_stream(bad_config);
bool failure = parser_.Parse(&config_stream, &output_config_);
EXPECT_FALSE(failure);
}
TEST_F(NginxConfigParserTest, MissingEndStatement){
std::string invalid_config =
"server {"
" /home/"
"}";
std::stringstream config_stream(invalid_config);
bool failure = parser_.Parse(&config_stream, &output_config_);
EXPECT_FALSE(failure);
}
TEST_F(NginxConfigParserTest, CheckOutputEq){
std::string small_config =
"server {"
" location {"
" /dev/null;"
" }"
"}"
"port 8008;";
std::stringstream config_stream(small_config);
bool mustBeTrue = parser_.Parse(&config_stream, &output_config_);
ASSERT_TRUE(mustBeTrue);
std::string result = output_config_.ToString();
EXPECT_EQ(result, "server {\n location {\n /dev/null;\n }\n}\nport 8008;\n");
}