@@ -314,6 +314,60 @@ func TestCreateWithNoSecurityGroup(t *testing.T) {
314314 })
315315}
316316
317+ func TestCreateWithValueSpecs (t * testing.T ) {
318+ th .SetupHTTP ()
319+ defer th .TeardownHTTP ()
320+
321+ th .Mux .HandleFunc ("/v2.0/ports" , func (w http.ResponseWriter , r * http.Request ) {
322+ th .TestMethod (t , r , "POST" )
323+ th .TestHeader (t , r , "X-Auth-Token" , fake .TokenID )
324+ th .TestHeader (t , r , "Content-Type" , "application/json" )
325+ th .TestHeader (t , r , "Accept" , "application/json" )
326+ th .TestJSONRequest (t , r , CreateValueSpecRequest )
327+
328+ w .Header ().Add ("Content-Type" , "application/json" )
329+ w .WriteHeader (http .StatusCreated )
330+
331+ fmt .Fprintf (w , CreateValueSpecResponse )
332+ })
333+
334+ asu := true
335+ options := ports.CreateOpts {
336+ Name : "private-port" ,
337+ AdminStateUp : & asu ,
338+ NetworkID : "a87cc70a-3e15-4acf-8205-9b711a3531b7" ,
339+ FixedIPs : []ports.IP {
340+ {SubnetID : "a0304c3a-4f08-4c43-88af-d796509c97d2" , IPAddress : "10.0.0.2" },
341+ },
342+ SecurityGroups : & []string {"foo" },
343+ AllowedAddressPairs : []ports.AddressPair {
344+ {IPAddress : "10.0.0.4" , MACAddress : "fa:16:3e:c9:cb:f0" },
345+ },
346+ ValueSpecs : & map [string ]string {
347+ "key" : "value" ,
348+ },
349+ }
350+ n , err := ports .Create (fake .ServiceClient (), options ).Extract ()
351+ th .AssertNoErr (t , err )
352+
353+ th .AssertEquals (t , n .Status , "DOWN" )
354+ th .AssertEquals (t , n .Name , "private-port" )
355+ th .AssertEquals (t , n .AdminStateUp , true )
356+ th .AssertEquals (t , n .NetworkID , "a87cc70a-3e15-4acf-8205-9b711a3531b7" )
357+ th .AssertEquals (t , n .TenantID , "d6700c0c9ffa4f1cb322cd4a1f3906fa" )
358+ th .AssertEquals (t , n .DeviceOwner , "" )
359+ th .AssertEquals (t , n .MACAddress , "fa:16:3e:c9:cb:f0" )
360+ th .AssertDeepEquals (t , n .FixedIPs , []ports.IP {
361+ {SubnetID : "a0304c3a-4f08-4c43-88af-d796509c97d2" , IPAddress : "10.0.0.2" },
362+ })
363+ th .AssertEquals (t , n .ID , "65c0ee9f-d634-4522-8954-51021b570b0d" )
364+ th .AssertDeepEquals (t , n .SecurityGroups , []string {"f0ac4394-7e4a-4409-9701-ba8be283dbc3" })
365+ th .AssertDeepEquals (t , n .AllowedAddressPairs , []ports.AddressPair {
366+ {IPAddress : "10.0.0.4" , MACAddress : "fa:16:3e:c9:cb:f0" },
367+ })
368+ th .AssertDeepEquals (t , n .ValueSpecs , map [string ]string {"key" : "value" })
369+ }
370+
317371func TestRequiredCreateOpts (t * testing.T ) {
318372 res := ports .Create (fake .ServiceClient (), ports.CreateOpts {})
319373 if res .Err == nil {
@@ -452,6 +506,35 @@ func TestUpdateOmitSecurityGroups(t *testing.T) {
452506 th .AssertDeepEquals (t , s .SecurityGroups , []string {"f0ac4394-7e4a-4409-9701-ba8be283dbc3" })
453507}
454508
509+ func TestUpdateValueSpecs (t * testing.T ) {
510+ th .SetupHTTP ()
511+ defer th .TeardownHTTP ()
512+
513+ th .Mux .HandleFunc ("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d" , func (w http.ResponseWriter , r * http.Request ) {
514+ th .TestMethod (t , r , "PUT" )
515+ th .TestHeader (t , r , "X-Auth-Token" , fake .TokenID )
516+ th .TestHeader (t , r , "Content-Type" , "application/json" )
517+ th .TestHeader (t , r , "Accept" , "application/json" )
518+ th .TestJSONRequest (t , r , UpdateValueSpecsRequest )
519+
520+ w .Header ().Add ("Content-Type" , "application/json" )
521+ w .WriteHeader (http .StatusOK )
522+
523+ fmt .Fprintf (w , UpdateValueSpecsResponse )
524+ })
525+
526+ options := ports.UpdateOpts {
527+ ValueSpecs : & map [string ]string {
528+ "key" : "value" ,
529+ },
530+ }
531+
532+ s , err := ports .Update (fake .ServiceClient (), "65c0ee9f-d634-4522-8954-51021b570b0d" , options ).Extract ()
533+ th .AssertNoErr (t , err )
534+
535+ th .AssertDeepEquals (t , s .ValueSpecs , map [string ]string {"key" : "value" })
536+ }
537+
455538func TestUpdatePortSecurity (t * testing.T ) {
456539 th .SetupHTTP ()
457540 defer th .TeardownHTTP ()
0 commit comments