From 423f5db8557505141deab46aade4f0a5d271ee24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 6 Jul 2025 03:46:29 +0000 Subject: [PATCH 1/2] Initial plan From 68fa1f1a18a0904d6004d9344ce03781298d1918 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 6 Jul 2025 03:52:12 +0000 Subject: [PATCH 2/2] Add network-ping CLI command feature Co-authored-by: j143 <53068787+j143@users.noreply.github.com> --- main.go | 10 ++++++++++ main_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/main.go b/main.go index ff97b2f..c3e9c4a 100644 --- a/main.go +++ b/main.go @@ -272,6 +272,15 @@ func main() { fmt.Printf("Error: %s\n", err) return } + case "network-ping": + if len(os.Args) < 5 { + fmt.Println("Usage: basic-docker network-ping ") + return + } + err := Ping(os.Args[2], os.Args[3], os.Args[4]) + if err != nil { + fmt.Printf("Error: %s\n", err) + } case "load": if len(os.Args) < 3 { fmt.Println("Error: Tar file path required for load") @@ -334,6 +343,7 @@ func printUsage() { fmt.Println(" basic-docker network-delete Delete a network by ID") fmt.Println(" basic-docker network-attach Attach a container to a network") fmt.Println(" basic-docker network-detach Detach a container from a network") + fmt.Println(" basic-docker network-ping Test connectivity between containers") fmt.Println(" basic-docker load Load an image from a tar file") fmt.Println(" basic-docker image rm Remove an image by name") } diff --git a/main_test.go b/main_test.go index 07a6785..f4807e0 100644 --- a/main_test.go +++ b/main_test.go @@ -305,4 +305,47 @@ func BenchmarkVolumeAttachment(b *testing.B) { b.Fatalf("Volume not found: %v", err) } } +} + +// TestNetworkPingCLI tests the network-ping CLI command functionality +func TestNetworkPingCLI(t *testing.T) { + // Cleanup: Ensure no existing networks interfere with the test + networks = []Network{} + saveNetworks() + + // Setup: Create a network and attach two containers + networkName := "test-cli-network" + CreateNetwork(networkName) + networkID := networks[0].ID + + container1 := "cli-container-1" + container2 := "cli-container-2" + + err := AttachContainerToNetwork(networkID, container1) + if err != nil { + t.Fatalf("Failed to attach container 1: %v", err) + } + + err = AttachContainerToNetwork(networkID, container2) + if err != nil { + t.Fatalf("Failed to attach container 2: %v", err) + } + + // Test successful ping - this directly tests the CLI function call + err = Ping(networkID, container1, container2) + if err != nil { + t.Errorf("CLI ping failed for containers in same network: %v", err) + } + + // Test ping with non-existent container + err = Ping(networkID, container1, "non-existent-container") + if err == nil { + t.Errorf("Expected CLI ping to fail for non-existent container, but it succeeded") + } + + // Test ping with non-existent network + err = Ping("non-existent-network", container1, container2) + if err == nil { + t.Errorf("Expected CLI ping to fail for non-existent network, but it succeeded") + } } \ No newline at end of file