Skip to content

Add network-ping CLI command to test container connectivity#14

Merged
j143 merged 2 commits intomainfrom
copilot/fix-6057cd3f-245d-4de6-8ba8-3ec0f4d6542b
Jul 6, 2025
Merged

Add network-ping CLI command to test container connectivity#14
j143 merged 2 commits intomainfrom
copilot/fix-6057cd3f-245d-4de6-8ba8-3ec0f4d6542b

Conversation

Copy link
Contributor

Copilot AI commented Jul 6, 2025

Summary

This PR adds a new network-ping CLI command that allows users to test connectivity between containers in a network from the command line. The feature exposes the existing Ping functionality through a user-friendly CLI interface.

Changes Made

New CLI Command

  • Added network-ping command: basic-docker network-ping <network-id> <source-container-id> <target-container-id>
  • Updated usage documentation: Added the new command to the help text in printUsage()
  • Follows existing patterns: Uses the same error handling and argument validation style as other network commands

Testing

  • Added TestNetworkPingCLI test: Comprehensive test covering success and error cases
  • All existing tests pass: No regression in functionality (9/9 tests passing)
  • Error handling tested: Validates proper error messages for invalid networks and containers

Usage Example

# Create a network and attach containers
./basic-docker network-create demo-network
./basic-docker network-attach net-1 container-a
./basic-docker network-attach net-1 container-b

# Test connectivity between containers
./basic-docker network-ping net-1 container-a container-b
# Output: Pinging from 192.168.1.2 to 192.168.1.3: Success

# Error cases are handled gracefully
./basic-docker network-ping net-1 container-a non-existent
# Output: Error: one or both containers are not in the network

Implementation Details

  • Minimal changes: Only 11 lines of new code in main.go plus test coverage
  • No breaking changes: Fully backward compatible with existing functionality
  • Reuses existing logic: Leverages the already-tested Ping() function from network.go
  • Consistent error handling: Follows the same error reporting pattern as other network commands

Validation

✅ All tests pass (including new test case)
✅ CLI command works correctly for success and error scenarios
✅ Help text updated to include new command
✅ Code follows existing style and patterns
✅ No impact on existing functionality

This enhancement makes the networking stack more complete by providing users with a simple way to verify container connectivity through the CLI, complementing the existing network management commands.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: j143 <53068787+j143@users.noreply.github.com>
Copilot AI changed the title [WIP] add a new feature Add network-ping CLI command to test container connectivity Jul 6, 2025
Copilot AI requested a review from j143 July 6, 2025 03:52
Copilot finished work on behalf of j143 July 6, 2025 03:52
Copy link
Owner

@j143 j143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@j143 j143 marked this pull request as ready for review July 6, 2025 04:03
@j143 j143 merged commit 36962ac into main Jul 6, 2025
2 checks passed
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.

2 participants