Skip to content

Commit

Permalink
Vpnaas: Delete service (#769)
Browse files Browse the repository at this point in the history
* Added delete request

* Added delete result

* added unit and acceptance tests for delete function

* added delete Service to acceptancetest

* Added documentation in doc.go file
  • Loading branch information
simonre authored and jtopjian committed Feb 21, 2018
1 parent bfeb72b commit d693a2e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestServiceCRUD(t *testing.T) {
if err != nil {
t.Fatalf("Unable to create service: %v", err)
}
defer DeleteService(t, client, service.ID)

tools.PrintResource(t, service)
}
14 changes: 14 additions & 0 deletions acceptance/openstack/networking/v2/extensions/vpnaas/vpnaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ func CreateService(t *testing.T, client *gophercloud.ServiceClient, routerID str

return service, nil
}

// DeleteService will delete a service with a specified ID. A fatal error
// will occur if the delete was not successful. This works best when used as
// a deferred function.
func DeleteService(t *testing.T, client *gophercloud.ServiceClient, serviceID string) {
t.Logf("Attempting to delete service: %s", serviceID)

err := services.Delete(client, serviceID).ExtractErr()
if err != nil {
t.Fatalf("Unable to delete service %s: %v", serviceID, err)
}

t.Logf("Service deleted: %s", serviceID)
}
8 changes: 8 additions & 0 deletions openstack/networking/v2/extensions/vpnaas/services/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ Example to Create a Service
panic(err)
}
Example to Delete a Service
serviceID := "38aee955-6283-4279-b091-8b9c828000ec"
err := policies.Delete(networkClient, serviceID).ExtractErr()
if err != nil {
panic(err)
}
*/
package services
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResul
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}

// Delete will permanently delete a particular VPN service based on its
// unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}
6 changes: 6 additions & 0 deletions openstack/networking/v2/extensions/vpnaas/services/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ func (r commonResult) Extract() (*Service, error) {
type CreateResult struct {
commonResult
}

// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the operation succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ func TestCreate(t *testing.T) {
}
th.AssertDeepEquals(t, expected, *actual)
}

func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

th.Mux.HandleFunc("/v2.0/vpn/vpnservices/5c561d9d-eaea-45f6-ae3e-08d1a7080828", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusNoContent)
})

res := services.Delete(fake.ServiceClient(), "5c561d9d-eaea-45f6-ae3e-08d1a7080828")
th.AssertNoErr(t, res.Err)
}

0 comments on commit d693a2e

Please sign in to comment.