Skip to content

Commit f342e3b

Browse files
committed
[WIP] Add first HTTP tests
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent ea07dbe commit f342e3b

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ endif()
7272
if(HYDRA_TESTS)
7373
find_package(GoogleTest REQUIRED)
7474
enable_testing()
75+
76+
if(HYDRA_HTTP)
77+
add_subdirectory(test/http)
78+
endif()
79+
7580
# TODO: Add tests
7681
if(PROJECT_IS_TOP_LEVEL)
7782
# Otherwise we need the child project to link

cmake/FindGoogleTest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include(GoogleTest)
12
set(BUILD_GMOCK OFF CACHE BOOL "disable googlemock")
23
set(INSTALL_GTEST OFF CACHE BOOL "disable installation")
34
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googletest")

test/http/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_executable(sourcemeta_hydra_http_unit
2+
http_1_1_test.cc)
3+
sourcemeta_hydra_add_compile_options(sourcemeta_hydra_http_unit)
4+
target_link_libraries(sourcemeta_hydra_http_unit
5+
PRIVATE GTest::gtest GTest::gtest_main)
6+
target_link_libraries(sourcemeta_hydra_http_unit
7+
PRIVATE sourcemeta::hydra::http)
8+
set_target_properties(sourcemeta_hydra_http_unit
9+
PROPERTIES FOLDER "Hydra/HTTP")
10+
gtest_discover_tests(sourcemeta_hydra_http_unit)

test/http/http_1_1_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <gtest/gtest.h>
2+
#include <sourcemeta/hydra/http.h>
3+
4+
TEST(Hydra_HTTP_1_1, XXX) { EXPECT_TRUE(true); }

test/http/stub_http1_1.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const port = 8080;
2+
3+
const handler = (request: Request): Response => {
4+
const body = `Your user-agent is:\n\n${
5+
request.headers.get("user-agent") ?? "Unknown"
6+
}`;
7+
8+
return new Response(body, { status: 200 });
9+
};
10+
11+
console.log(`HTTP server running. Access it at: http://localhost:8080/`);
12+
Deno.serve({ port }, handler);

0 commit comments

Comments
 (0)