diff --git a/test/integration/kic_custom_network_test.go b/test/integration/kic_custom_network_test.go index b392336532..18c92d1c9d 100644 --- a/test/integration/kic_custom_network_test.go +++ b/test/integration/kic_custom_network_test.go @@ -75,7 +75,7 @@ func TestKicExistingNetwork(t *testing.T) { } // create custom network networkName := "existing-network" - if _, err := oci.CreateNetwork(oci.Docker, networkName); err != nil { + if _, err := oci.CreateNetwork(oci.Docker, networkName, ""); err != nil { t.Fatalf("error creating network: %v", err) } defer func() { @@ -97,6 +97,27 @@ func TestKicExistingNetwork(t *testing.T) { } } +// TestKicCustomSubnet verifies the docker/podman driver works with a custom subnet +func TestKicCustomSubnet(t *testing.T) { + if !KicDriver() { + t.Skip("only runs with docker/podman driver") + } + + profile := UniqueProfileName("custom-subnet") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(5)) + defer Cleanup(t, profile, cancel) + + subnet := "192.168.60.0/24" + startArgs := []string{"start", "-p", profile, fmt.Sprintf("--subnet=%s", subnet)} + c := exec.CommandContext(ctx, Target(), startArgs...) + rr, err := Run(t, c) + if err != nil { + t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output()) + } + + verifySubnet(ctx, t, profile, subnet) +} + func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string) { c := exec.CommandContext(ctx, "docker", "network", "ls", "--format", "{{.Name}}") rr, err := Run(t, c) @@ -107,3 +128,15 @@ func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string) t.Fatalf("%s network is not listed by [%v]: %v", networkName, c.Args, output) } } + +func verifySubnet(ctx context.Context, t *testing.T, network, subnet string) { + c := exec.CommandContext(ctx, "docker", "network", "inspect", network, "--format", "{{(index .IPAM.Config 0).Subnet}}") + rr, err := Run(t, c) + if err != nil { + t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output()) + } + + if output := strings.TrimSpace(rr.Output()); !strings.Contains(output, subnet) { + t.Fatalf("%s subnet not match to %v", subnet, output) + } +}