@@ -391,6 +391,60 @@ func TestCreateNoGateway(t *testing.T) {
391391 th .AssertEquals (t , s .ID , "54d6f61d-db07-451c-9ab3-b9609b6b6f0c" )
392392}
393393
394+ func TestCreateInvalidGatewayConfig (t * testing.T ) {
395+ th .SetupHTTP ()
396+ defer th .TeardownHTTP ()
397+
398+ th .Mux .HandleFunc ("/v2.0/subnets" , func (w http.ResponseWriter , r * http.Request ) {
399+ th .TestMethod (t , r , "POST" )
400+ th .TestHeader (t , r , "X-Auth-Token" , fake .TokenID )
401+ th .TestHeader (t , r , "Content-Type" , "application/json" )
402+ th .TestHeader (t , r , "Accept" , "application/json" )
403+ th .TestJSONRequest (t , r , `
404+ {
405+ "subnet": {
406+ "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a23",
407+ "ip_version": 4,
408+ "cidr": "192.168.1.0/24",
409+ "gateway_ip": "192.168.1.1",
410+ "allocation_pools": [
411+ {
412+ "start": "192.168.1.2",
413+ "end": "192.168.1.254"
414+ }
415+ ]
416+ }
417+ }
418+ ` )
419+
420+ w .Header ().Add ("Content-Type" , "application/json" )
421+ w .WriteHeader (http .StatusCreated )
422+ })
423+
424+ opts := CreateOpts {
425+ NetworkID : "d32019d3-bc6e-4319-9c1d-6722fc136a23" ,
426+ IPVersion : 4 ,
427+ CIDR : "192.168.1.0/24" ,
428+ NoGateway : true ,
429+ GatewayIP : "192.168.1.1" ,
430+ AllocationPools : []AllocationPool {
431+ AllocationPool {
432+ Start : "192.168.1.2" ,
433+ End : "192.168.1.254" ,
434+ },
435+ },
436+ DNSNameservers : []string {},
437+ }
438+ _ , err := Create (fake .ServiceClient (), opts ).Extract ()
439+ if err == nil {
440+ t .Fatalf ("Expected an error, got none" )
441+ }
442+
443+ if err != errInvalidGatewayConfig {
444+ t .Fatalf ("Exected errInvalidGateway but got: %s" , err )
445+ }
446+ }
447+
394448func TestRequiredCreateOpts (t * testing.T ) {
395449 res := Create (fake .ServiceClient (), CreateOpts {})
396450 if res .Err == nil {
0 commit comments