-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from jhiemstrawisc/issue-17
Add very basic unit tests for S3 and HTTP
- Loading branch information
Showing
7 changed files
with
234 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
add_executable( s3-gtest s3_tests.cc | ||
../src/AWSv4-impl.cc | ||
../src/logging.cc | ||
../src/S3AccessInfo.cc | ||
../src/S3File.cc | ||
../src/S3FileSystem.cc | ||
../src/shortfile.cc | ||
../src/stl_string_utils.cc | ||
../src/HTTPCommands.cc | ||
../src/S3Commands.cc | ||
) | ||
|
||
add_executable( http-gtest http_tests.cc | ||
../src/HTTPFile.cc | ||
../src/HTTPFileSystem.cc | ||
../src/HTTPCommands.cc | ||
../src/stl_string_utils.cc | ||
../src/shortfile.cc | ||
../src/logging.cc | ||
) | ||
|
||
|
||
if( NOT XROOTD_PLUGINS_EXTERNAL_GTEST ) | ||
add_dependencies(s3-gtest gtest) | ||
add_dependencies(http-gtest gtest) | ||
include_directories("${PROJECT_SOURCE_DIR}/vendor/gtest/googletest/include") | ||
endif() | ||
|
||
if(XROOTD_PLUGINS_EXTERNAL_GTEST) | ||
set(LIBGTEST "gtest") | ||
else() | ||
set(LIBGTEST "${CMAKE_BINARY_DIR}/external/gtest/src/gtest-build/lib/libgtest.a") | ||
endif() | ||
|
||
target_link_libraries(s3-gtest XrdS3 "${LIBGTEST}" pthread) | ||
target_link_libraries(http-gtest XrdHTTPServer "${LIBGTEST}" pthread) | ||
|
||
|
||
add_test( | ||
NAME | ||
s3-unit | ||
COMMAND | ||
${CMAKE_CURRENT_BINARY_DIR}/s3-gtest | ||
) | ||
|
||
add_test( | ||
NAME | ||
http-unit | ||
COMMAND | ||
${CMAKE_CURRENT_BINARY_DIR}/http-gtest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*************************************************************** | ||
* | ||
* Copyright (C) 2024, Pelican Project, Morgridge Institute for Research | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you | ||
* may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
***************************************************************/ | ||
|
||
#include "../src/HTTPCommands.hh" | ||
|
||
#include <XrdSys/XrdSysError.hh> | ||
#include <XrdSys/XrdSysLogger.hh> | ||
#include <gtest/gtest.h> | ||
|
||
class TestHTTPRequest : public HTTPRequest { | ||
public: | ||
XrdSysLogger log{}; | ||
XrdSysError err{&log, "TestS3CommandsLog"}; | ||
|
||
TestHTTPRequest(const std::string &url) : HTTPRequest(url, err) {} | ||
}; | ||
|
||
TEST(TestHTTPParseProtocol, Test1) { | ||
const std::string httpURL = "https://my-test-url.com:443"; | ||
TestHTTPRequest req{httpURL}; | ||
|
||
// Test parsing of https | ||
std::string protocol; | ||
req.parseProtocol("https://my-test-url.com:443", protocol); | ||
ASSERT_EQ(protocol, "https"); | ||
|
||
// Test parsing for http | ||
req.parseProtocol("http://my-test-url.com:443", protocol); | ||
ASSERT_EQ(protocol, "http"); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
Oops, something went wrong.