-
Notifications
You must be signed in to change notification settings - Fork 1
Add testing fixture for Assuan client and server #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cottsay
wants to merge
2
commits into
main
Choose a base branch
from
cottsay/integration-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,30 @@ | ||
// Copyright 2025 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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 <assuan.h> | ||
#include <gpgme.h> | ||
#include <gtest/gtest.h> | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
int ret; | ||
|
||
gpgrt_check_version(NULL); | ||
gpgme_check_version(NULL); | ||
assuan_sock_init(); | ||
::testing::InitGoogleTest(&argc, argv); | ||
ret = RUN_ALL_TESTS(); | ||
assuan_sock_deinit(); | ||
return ret; | ||
} |
This file contains hidden or 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,107 @@ | ||
// Copyright 2025 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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 <assuan.h> | ||
#include <algorithm> | ||
#include <chrono> | ||
#include <string> | ||
#include <thread> | ||
|
||
#include "createrepo-agent/command.h" | ||
#include "createrepo-agent/common.h" | ||
#include "createrepo-agent/server.h" | ||
#include "utils.hpp" | ||
|
||
#ifndef INTEGRATION_UTILS_HPP_ | ||
#define INTEGRATION_UTILS_HPP_ | ||
|
||
namespace fs = std::filesystem; | ||
|
||
class TempRepo : public TempDir, public testing::WithParamInterface<std::string_view> | ||
{ | ||
public: | ||
static | ||
std::string | ||
PrintParamName(const testing::TestParamInfo<ParamType> & info) | ||
{ | ||
return std::string(info.param); | ||
} | ||
|
||
protected: | ||
void | ||
SetUp() override | ||
{ | ||
fs::path fixture = fs::absolute("fixtures") / GetParam(); | ||
ASSERT_TRUE(fs::is_directory(fixture)); | ||
|
||
TempDir::SetUp(); | ||
|
||
fs::copy(fixture, temp_dir); | ||
} | ||
}; | ||
|
||
class CRATempServer : public TempRepo | ||
{ | ||
protected: | ||
void | ||
SetUp() override | ||
{ | ||
TempRepo::SetUp(); | ||
ASSERT_FALSE(assuan_new(&client)); | ||
|
||
sock_path = temp_dir / CRA_SOCK_NAME; | ||
|
||
server_fd = create_server_socket(sock_path.c_str()); | ||
ASSERT_NE(server_fd, ASSUAN_INVALID_FD); | ||
|
||
/* Start the server thread */ | ||
handler_thread = std::thread(command_handler, server_fd, temp_dir.c_str()); | ||
|
||
/* Wait for client to connect */ | ||
for (int i = 0; assuan_socket_connect(client, sock_path.c_str(), ASSUAN_INVALID_PID, 0); i++) { | ||
ASSERT_LT(i, 10); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
} | ||
} | ||
|
||
void | ||
TearDown() override | ||
{ | ||
if (!::testing::Test::HasFailure()) { | ||
EXPECT_FALSE(assuan_transact(client, "SHUTDOWN", NULL, NULL, NULL, NULL, NULL, NULL)); | ||
assuan_release(client); | ||
} | ||
|
||
if (::testing::Test::HasFailure()) { | ||
/* Something has already failed. Detach the server thread and let it | ||
* die independently so that we don't clobber the real failure */ | ||
handler_thread.detach(); | ||
} else { | ||
handler_thread.join(); | ||
assuan_sock_close(server_fd); | ||
server_fd = ASSUAN_INVALID_FD; | ||
} | ||
|
||
TempRepo::TearDown(); | ||
} | ||
|
||
fs::path sock_path; | ||
assuan_context_t client; | ||
|
||
private: | ||
assuan_fd_t server_fd = ASSUAN_INVALID_FD; | ||
std::thread handler_thread; | ||
}; | ||
|
||
#endif // INTEGRATION_UTILS_HPP_ |
This file contains hidden or 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,25 @@ | ||
// Copyright 2025 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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 <gtest/gtest.h> | ||
|
||
#include "integration_utils.hpp" | ||
|
||
class smoke : public CRATempServer {}; | ||
|
||
TEST_P(smoke, commit) { | ||
gpg_error_t rc = assuan_transact(client, "COMMIT", NULL, NULL, NULL, NULL, NULL, NULL); | ||
EXPECT_FALSE(rc); | ||
} | ||
INSTANTIATE_TEST_SUITE_P( , smoke, testing::Values("empty", "populated"), smoke::PrintParamName); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty bare example of how the fixture can be used.
In the test body, you have a running CRA server (in another thread) and an already connected client context. The fixture directory has already been copied to a temporary directory, so you can modify it as part of the test or test setup. The client and server will be terminated gracefully during the test tear-down.
Note that even though the CRA server has been started, it hasn't actually loaded any repository metadata, so you can absolutely modify it in the test body to set up the test as long as you haven't invoked any operations that would load the metadata first.