@@ -75,7 +75,7 @@ func TestKicExistingNetwork(t *testing.T) {
75
75
}
76
76
// create custom network
77
77
networkName := "existing-network"
78
- if _ , err := oci .CreateNetwork (oci .Docker , networkName ); err != nil {
78
+ if _ , err := oci .CreateNetwork (oci .Docker , networkName , "" ); err != nil {
79
79
t .Fatalf ("error creating network: %v" , err )
80
80
}
81
81
defer func () {
@@ -97,6 +97,27 @@ func TestKicExistingNetwork(t *testing.T) {
97
97
}
98
98
}
99
99
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
+
100
121
func verifyNetworkExists (ctx context.Context , t * testing.T , networkName string ) {
101
122
c := exec .CommandContext (ctx , "docker" , "network" , "ls" , "--format" , "{{.Name}}" )
102
123
rr , err := Run (t , c )
@@ -107,3 +128,15 @@ func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string)
107
128
t .Fatalf ("%s network is not listed by [%v]: %v" , networkName , c .Args , output )
108
129
}
109
130
}
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