Skip to content

Commit

Permalink
add test for 'subnet' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
presztak committed Mar 15, 2022
1 parent f3c9198 commit eb19396
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/integration/kic_custom_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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)
}
}

0 comments on commit eb19396

Please sign in to comment.