File tree Expand file tree Collapse file tree 9 files changed +68
-2
lines changed Expand file tree Collapse file tree 9 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 57
57
steps :
58
58
- name : Install dependencies (GNU/Linux)
59
59
if : runner.os == 'linux'
60
- run : sudo apt-get install --yes clang-format libcurl4-openssl-dev
60
+ run : sudo apt-get install --yes clang-format libcurl4-openssl-dev nodejs
61
61
62
62
# See https://github.com/actions/runner-images/issues/8659
63
63
- name : Workaround Clang issue (GNU/Linux)
@@ -105,6 +105,14 @@ jobs:
105
105
cmake --install ./build --prefix ./build/dist --config Release --verbose
106
106
--component sourcemeta_hydra_dev
107
107
108
+ # Run stubs
109
+ - name : Run HTTP stub (Windows)
110
+ run : cmd /c "start /b node test\http\stub.js" && Start-Sleep -Seconds 2
111
+ if : runner.os == 'windows'
112
+ - name : Run HTTP stub (*nix)
113
+ run : (node test/http/stub.js &) && sleep 2
114
+ if : runner.os != 'windows'
115
+
108
116
# Not every CTest version supports the --test-dir option. If such option
109
117
# is not recognized, `ctest` will successfully exit finding no tests.
110
118
# Better to be sure and `cd` all the time here.
Original file line number Diff line number Diff line change 1
1
brew "cmake"
2
2
brew "clang-format"
3
3
brew "doxygen"
4
+ brew "node"
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ endif()
73
73
if (HYDRA_TESTS )
74
74
find_package (GoogleTest REQUIRED )
75
75
enable_testing ()
76
+
77
+ if (HYDRA_HTTP )
78
+ add_subdirectory (test /http )
79
+ endif ()
80
+
76
81
# TODO: Add tests
77
82
if (PROJECT_IS_TOP_LEVEL )
78
83
# Otherwise we need the child project to link
Original file line number Diff line number Diff line change 1
1
# Programs
2
2
CMAKE = cmake
3
3
CTEST = ctest
4
+ # For test server
5
+ NODE = node
6
+ KILLALL = killall
7
+ SLEEP = sleep
4
8
5
9
# Options
6
10
PRESET = Debug
@@ -30,10 +34,14 @@ compile: .always
30
34
lint : .always
31
35
$(CMAKE ) --build ./build --config $(PRESET ) --target clang_tidy
32
36
33
- test : .always
37
+ test : test/http/stub.js .always
38
+ $(KILLALL ) $(NODE ) || true
39
+ $(NODE ) $< &
40
+ $(SLEEP ) 1
34
41
$(CMAKE ) -E env UBSAN_OPTIONS=print_stacktrace=1 \
35
42
$(CTEST ) --test-dir ./build --build-config $(PRESET ) \
36
43
--output-on-failure --progress --parallel
44
+ $(KILLALL ) $(NODE )
37
45
38
46
doxygen : .always
39
47
$(CMAKE ) --build ./build --config $(PRESET ) --target doxygen
Original file line number Diff line number Diff line change
1
+ include (GoogleTest )
1
2
set (BUILD_GMOCK OFF CACHE BOOL "disable googlemock" )
2
3
set (INSTALL_GTEST OFF CACHE BOOL "disable installation" )
3
4
add_subdirectory ("${PROJECT_SOURCE_DIR} /vendor/googletest" )
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ cmake --build ./build --config <Debug|Release> --target clang_format
120
120
# Build the project
121
121
cmake --build ./build --config <Debug|Release>
122
122
# Run the test suite
123
+ node test/http/stub.js
123
124
ctest --test-dir ./build --build-config <Debug|Release> --output-on-failure --progress
124
125
` ` `
125
126
Original file line number Diff line number Diff line change
1
+ # Tests
2
+ add_executable (sourcemeta_hydra_http_unit
3
+ request_1_1_test.cc )
4
+ sourcemeta_hydra_add_compile_options (sourcemeta_hydra_http_unit )
5
+ target_compile_definitions (sourcemeta_hydra_http_unit PRIVATE
6
+ BASE_URL= "http://localhost:9999" )
7
+ target_link_libraries (sourcemeta_hydra_http_unit
8
+ PRIVATE GTest::gtest GTest::gtest_main )
9
+ target_link_libraries (sourcemeta_hydra_http_unit
10
+ PRIVATE sourcemeta::hydra::http )
11
+ set_target_properties (sourcemeta_hydra_http_unit
12
+ PROPERTIES FOLDER "Hydra/HTTP" )
13
+ gtest_discover_tests (sourcemeta_hydra_http_unit )
Original file line number Diff line number Diff line change
1
+ #include < gtest/gtest.h>
2
+ #include < sourcemeta/hydra/http.h>
3
+
4
+ TEST (HTTP_Request_1_1, XXX) {
5
+ sourcemeta::hydra::http::Request request{BASE_URL};
6
+ request.method (sourcemeta::hydra::http::Method::GET);
7
+ sourcemeta::hydra::http::Response response{request.send ().get ()};
8
+ EXPECT_EQ (response.status (), sourcemeta::hydra::http::Status::OK);
9
+ }
Original file line number Diff line number Diff line change
1
+ const http = require ( 'http' ) ;
2
+
3
+ const server = http . createServer ( ( req , res ) => {
4
+ // Set the response header to indicate JSON content
5
+ res . setHeader ( 'Content-Type' , 'application/json' ) ;
6
+
7
+ // Define a simple JSON response
8
+ const jsonResponse = {
9
+ message : 'Hello, JSON World!' ,
10
+ timestamp : new Date ( ) . toISOString ( ) ,
11
+ } ;
12
+
13
+ // Send the JSON response
14
+ res . end ( JSON . stringify ( jsonResponse ) ) ;
15
+ } ) ;
16
+
17
+ const PORT = 9999 ;
18
+ server . listen ( PORT , ( ) => {
19
+ console . log ( `Server is listening on port ${ PORT } ` ) ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments