Skip to content

Commit 2d0ea69

Browse files
committed
add test for 'subnet' flag
1 parent db0f955 commit 2d0ea69

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Diff for: test/integration/kic_custom_network_test.go

+34-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestKicExistingNetwork(t *testing.T) {
7575
}
7676
// create custom network
7777
networkName := "existing-network"
78-
if _, err := oci.CreateNetwork(oci.Docker, networkName); err != nil {
78+
if _, err := oci.CreateNetwork(oci.Docker, networkName, ""); err != nil {
7979
t.Fatalf("error creating network: %v", err)
8080
}
8181
defer func() {
@@ -97,6 +97,27 @@ func TestKicExistingNetwork(t *testing.T) {
9797
}
9898
}
9999

100+
// TestKicCustomSubnet verifies the docker/podman driver works with a custom subnet
101+
func TestKicCustomSubnet(t *testing.T) {
102+
if !KicDriver() {
103+
t.Skip("only runs with docker/podman driver")
104+
}
105+
106+
profile := UniqueProfileName("custom-subnet")
107+
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5))
108+
defer Cleanup(t, profile, cancel)
109+
110+
subnet := "192.168.60.0/24"
111+
startArgs := []string{"start", "-p", profile, fmt.Sprintf("--subnet=%s", subnet)}
112+
c := exec.CommandContext(ctx, Target(), startArgs...)
113+
rr, err := Run(t, c)
114+
if err != nil {
115+
t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output())
116+
}
117+
118+
verifySubnet(ctx, t, profile, subnet)
119+
}
120+
100121
func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string) {
101122
c := exec.CommandContext(ctx, "docker", "network", "ls", "--format", "{{.Name}}")
102123
rr, err := Run(t, c)
@@ -107,3 +128,15 @@ func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string)
107128
t.Fatalf("%s network is not listed by [%v]: %v", networkName, c.Args, output)
108129
}
109130
}
131+
132+
func verifySubnet(ctx context.Context, t *testing.T, network string, subnet string) {
133+
c := exec.CommandContext(ctx, "docker", "network", "inspect", network, "--format", "{{(index .IPAM.Config 0).Subnet}}")
134+
rr, err := Run(t, c)
135+
if err != nil {
136+
t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output())
137+
}
138+
139+
if output := strings.TrimSpace(rr.Output()); !strings.Contains(output, subnet) {
140+
t.Fatalf("%s subnet not match to %v", subnet, output)
141+
}
142+
}

0 commit comments

Comments
 (0)