Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an isolated GoogleTest suite for src/pfctl.cpp by introducing a Python-based pfctl mock and a small production change to allow overriding the pfctl executable path at runtime.
Changes:
- Introduce
tests/mock_pfctl.pyand newPfctlTestfixture + test suite covering table ops, kill commands, andpf_sync_table()behavior. - Add
pfctl_commandoverride insrc/pfctl.cpp/src/pfctl.h(defaulting to/sbin/pfctl) so tests can run against the mock. - Split the test CMake target into
testtool_test_poolandtesttool_test_pfctl, and updatechecktarget dependencies accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/pfctl_test.h | Adds a GTest fixture that sets up temp state and points pfctl_command at the mock script. |
| tests/pfctl_test.cpp | Adds extensive unit tests for pfctl helper functions using the mock’s JSON state. |
| tests/mock_pfctl.py | Implements a minimal pfctl simulator for table and kill operations. |
| src/pfctl.h | Exposes pfctl_command and changes pf_get_table signature to match pointer-style usage. |
| src/pfctl.cpp | Uses pfctl_command instead of hardcoding /sbin/pfctl. |
| CMakeLists.txt | Creates separate executables for pool vs pfctl tests and updates check target. |
| CLAUDE.md | Adds developer documentation on build/test workflow and architecture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+49
to
+51
| virtual void TearDown() override { | ||
| unlink(state_file.c_str()); | ||
| } |
Comment on lines
+297
to
+309
| // Helper to build SyncedLbNode array | ||
| static void InitSyncedNodes(SyncedLbNode *nodes) { | ||
| memset(nodes, 0, sizeof(SyncedLbNode) * MAX_NODES); | ||
| } | ||
|
|
||
| static void SetSyncedNode(SyncedLbNode *nodes, int index, | ||
| const char *address, LbNodeState wanted, | ||
| LbNodeAdminState admin) { | ||
| if (address) | ||
| strncpy(nodes[index].ip_address[1], address, ADDR_LEN); | ||
| nodes[index].wanted_state = wanted; | ||
| nodes[index].admin_state = admin; | ||
| } |
Add pfctl tests using a mock pfctl Python script Make the pfctl binary path configurable so tests can substitute a mock implementation. The mock script (tests/mock_pfctl.py) uses argparse to simulate pfctl table and kill operations, storing state in a temporary JSON file. This tests real process spawning via popen() without requiring FreeBSD. 32 new tests cover all functions in pfctl.cpp: pfctl_run_command, pf_table_add, pf_table_del, pf_kill_src_nodes_to, pf_kill_states_to_rdr, pf_get_table, pf_is_in_table, pf_table_rebalance, and pf_sync_table. Also renames the test binary from testtool_test to testtool_test_pool and fixes the pf_get_table declaration in pfctl.h to match the implementation signature.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.