Skip to content

feat(test): add unit and integration tests for mini_buffer, SSH session, and connection manager - #5

Merged
ohto-ai merged 2 commits into
masterfrom
copilot/add-test-for-login-behavior
Apr 2, 2026
Merged

ohto-ai merged 2 commits into
masterfrom
copilot/add-test-for-login-behavior

Conversation

Copilot AI commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

The project had only a placeholder test (REQUIRE(true == true)), with no coverage of the SSH login flow, connection state, or lifecycle behavior.

Build system

  • CMakeLists.txt: Move enable_testing() to the top level so ctest discovers tests from the project root.
  • src/CMakeLists.txt: Extract ssh_connection.cpp into a static library webssh_cpp_ssh_lib with PUBLIC include paths, shared between the main executable and test targets.
  • test/CMakeLists.txt: Link all test executables against webssh_cpp_ssh_lib (transitively pulls in libssh2 + spdlog). Rename the custom target to avoid conflict with CTest's reserved test target.

Bug fix

ssh_pty_connection_manager::close_channel() was declared in the header but never implemented. Added the implementation: looks up the channel by ID, erases it from the manager's weak-pointer map, then calls close() to trigger the session cleanup chain.

New tests

File Coverage
test/mini_buffer.test.cpp 8 cases / 42 assertions — constructors, reserve, resize, clear, append, move semantics, implicit char* conversion
test/ssh_session.test.cpp 13 cases — generate_id() variants, ssh_pty_connection_manager defaults and state (max channels, unknown ID lookups)
test/ssh_connection.test.cpp 9 integration cases — full login/auth flow, wrong-password rejection, bad-host failure, channel lifecycle, PTY+shell, resize, session pooling

Integration tests skip gracefully when TEST_SSH_HOST / TEST_SSH_USER / TEST_SSH_PASS are not set:

auto cfg = get_ssh_config();
if (!cfg.available) {
    WARN("Skipping SSH integration tests: TEST_SSH_HOST / TEST_SSH_USER / TEST_SSH_PASS not set");
    return;
}
// ... full connect → authenticate → open_channel → shell → close flow

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
…on, and connection manager

- Move enable_testing() to top-level CMakeLists.txt for ctest discovery
- Extract ssh_connection.cpp into webssh_cpp_ssh_lib static library for test reuse
- Update test/CMakeLists.txt to link against webssh_cpp_ssh_lib
- Implement ssh_pty_connection_manager::close_channel() (was declared but missing)
- Add test/mini_buffer.test.cpp (8 test cases, 42 assertions)
- Add test/ssh_session.test.cpp (13 test cases, 14 assertions)
- Add test/ssh_connection.test.cpp (9 integration test cases, skipped without env vars)

Agent-Logs-Url: https://github.com/ohto-ai/webssh_cpp/sessions/87b032af-b1d4-43eb-95f2-5f7937532073

Co-authored-by: ohto-ai <46275725+ohto-ai@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for login behavior using mock user creation feat(test): add unit and integration tests for mini_buffer, SSH session, and connection manager Apr 2, 2026
Copilot AI requested a review from ohto-ai April 2, 2026 02:32
@ohto-ai
ohto-ai marked this pull request as ready for review April 2, 2026 15:26
@ohto-ai
ohto-ai merged commit fdcb3e0 into master Apr 2, 2026
9 checks passed
@ohto-ai
ohto-ai deleted the copilot/add-test-for-login-behavior branch April 2, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 [REQUEST] - 增加Test

2 participants