Skip to content

Commit 698e355

Browse files
committed
Added proxy unit tests to make file
1 parent fda131d commit 698e355

7 files changed

+20
-226
lines changed

Diff for: Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ test: lib
4444
$(MAKE) -C test
4545
cd bin && ./webserver_tests
4646

47+
.PHONY: proxy-test
48+
proxy-test: lib
49+
$(MAKE) -C src test
50+
$(MAKE) -C test
51+
cd bin && ./proxy_webserver_tests
52+
4753
.PHONY: int-test
4854
int-test: test
4955
scripts/integration.sh && scripts/multithread_test.sh && scripts/proxy_integration_test.sh
5056

51-
.PHONY: proxy-test
52-
proxy-test: lib
57+
.PHONY: prox-int-test
58+
proxy-int-test: lib
5359
scripts/proxy_integration_test.sh
5460

5561
.PHONY: proxy-302-test

Diff for: bin/proxy_webserver_tests

6.56 MB
Binary file not shown.

Diff for: scripts/integration.sh

-12
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ fi
5656
# run server in background
5757
bin/webserver $CONFIG_FILE 2>&1 >/dev/null &
5858

59-
# integration test for reverse proxy
60-
61-
proxy_response="$(curl --silent -I localhost:${PORT}/proxy | head -n 1 | tr -d '\r\n')"
62-
63-
if [ "$proxy_response" != "HTTP/1.1 200 OK" ]; then
64-
echo "Reverse Proxy Test failed - got different response than expected."
65-
echo "$proxy_response"
66-
EXIT_STATUS=1
67-
else
68-
echo "Reverse Proxy Test Passed."
69-
fi
70-
7159
good_response="GET /echo1 HTTP/1.1\r\nUser-Agent: Mozilla/4.0\r\n"
7260
good_response="${good_response}Host: localhost:8080\r\nAccept: */*\r\n\r\n"
7361
# turn C-style escape sequences into actual carriage returns and newlines

Diff for: scripts/proxy_integration_test.sh~

-106
This file was deleted.

Diff for: scripts/proxy_integration_test_cp.sh

-95
This file was deleted.

Diff for: test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ TEST_DEP_OBJECTS=$(OBJ_DIR)/config_parser.o
1616

1717
TEST_SOURCES=$(wildcard *.cc)
1818
TEST_OBJECTS=$(patsubst %.cc,$(OBJ_DIR)/%.o,$(TEST_SOURCES))
19+
PROXY_TEST_OBJECT=$(OBJ_DIR)/proxy_handler_test.o
1920

2021
SOURCES=$(wildcard $(SRC_DIR)/*.cc) \
2122
$(wildcard $(SRC_DIR)/http/*.cc) \
@@ -35,7 +36,7 @@ $(EXECUTABLE): $(TEST_OBJECTS) $(SOURCE_OBJECTS) $(TEST_DEP_OBJECTS)
3536
echo $(SOURCE_OBJECTS)
3637
$(CXX) $^ $(GTEST_LIBS) -o $@ $(TEST_LDFLAGS)
3738

38-
$(PROXY_HANDLER_EXECUTABLE): $(OBJ_DIR/proxy_handler_test.o) $(SOURCE_OBJECTS) $(TEST_DEP_OBJECTS)
39+
$(PROXY_HANDLER_EXECUTABLE): $(PROXY_TEST_OBJECT) $(SOURCE_OBJECTS) $(TEST_DEP_OBJECTS)
3940
echo $(SOURCE_OBJECTS)
4041
$(CXX) $^ $(GTEST_LIBS) -o $@ $(TEST_LDFLAGS)
4142

Diff for: test/proxy_handler_test.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ProxyHandlerTest : public ::testing::Test {
88
public:
9-
ProxyHandler* handler_;
9+
ProxyHandler* handler_;
1010
NginxConfigParser parser_;
1111
NginxConfig config_;
1212

@@ -24,14 +24,14 @@ class ProxyHandlerTest : public ::testing::Test {
2424
return true;
2525
}
2626

27-
std::unique_ptr<Request> GetClientRequest() {
28-
std::string request_str = \
29-
"GET /proxy/path/to/some_file HTTP/1.1\r\n"
30-
"Content-Type: text/plain\r\n\r\n"
31-
"I AM A BODY!";
32-
auto r = Request::Parse(request_str);
33-
return r;
34-
}
27+
std::unique_ptr<Request> GetClientRequest() {
28+
std::string request_str = \
29+
"GET /proxy/path/to/some_file HTTP/1.1\r\n"
30+
"Content-Type: text/plain\r\n\r\n"
31+
"I AM A BODY!";
32+
auto r = Request::Parse(request_str);
33+
return r;
34+
}
3535

3636
std::unique_ptr<Response> GetResponse() {
3737
std::string response_str = \
@@ -49,7 +49,7 @@ TEST_F(ProxyHandlerTest, ProxyHandlerInitTest) {
4949

5050
TEST_F(ProxyHandlerTest, RequestTransformationTest) {
5151
EXPECT_TRUE(CreateProxyHandlerTest());
52-
auto req = GetClientRequest();
52+
auto req = GetClientRequest();
5353
auto proxy_req = handler_->CreateProxyRequestFromClientRequest(*req, "localhost:8080");
5454
EXPECT_EQ("/path/to/some_file", proxy_req->uri());
5555
}

0 commit comments

Comments
 (0)