77 "github.com/gophercloud/gophercloud/v2"
88 "github.com/gophercloud/gophercloud/v2/internal/acceptance/tools"
99 "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/domains"
10+ "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/endpoints"
1011 "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/groups"
1112 "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/projects"
1213 "github.com/gophercloud/gophercloud/v2/openstack/identity/v3/regions"
@@ -17,6 +18,38 @@ import (
1718 th "github.com/gophercloud/gophercloud/v2/testhelper"
1819)
1920
21+ // CreateEndpoint will create an endpoint with a random name. It only define
22+ // endpoint name and description, and receive from CreateOpts others parameters,
23+ // such as URL, Availability and ServiceID. An error will be returned if the
24+ // endpoint was unabled to be created.
25+ func CreateEndpoint (t * testing.T , client * gophercloud.ServiceClient , c * endpoints.CreateOpts ) (* endpoints.Endpoint , error ) {
26+ name := tools .RandomString ("ACPTTEST" , 8 )
27+ description := tools .RandomString ("ACPTTEST-DESC" , 8 )
28+ t .Logf ("Attempting to create endpoint: %s" , name )
29+
30+ var createOpts endpoints.CreateOpts
31+ if c != nil {
32+ createOpts = * c
33+ } else {
34+ createOpts = endpoints.CreateOpts {}
35+ }
36+
37+ createOpts .Name = name
38+ createOpts .Description = description
39+
40+ endpoint , err := endpoints .Create (context .TODO (), client , createOpts ).Extract ()
41+ if err != nil {
42+ return endpoint , err
43+ }
44+
45+ t .Logf ("Successfully created endpoint %s with ID %s" , name , endpoint .ID )
46+
47+ th .AssertEquals (t , endpoint .Name , name )
48+ th .AssertEquals (t , endpoint .Description , description )
49+
50+ return endpoint , nil
51+ }
52+
2053// CreateProject will create a project with a random name.
2154// It takes an optional createOpts parameter since creating a project
2255// has so many options. An error will be returned if the project was
@@ -228,6 +261,18 @@ func CreateService(t *testing.T, client *gophercloud.ServiceClient, c *services.
228261 return service , nil
229262}
230263
264+ // DeleteEndpoint will delete the specified Endpoint using its ID. A fatal error
265+ // will occur if the endpoint failed to be deleted. This works best when using
266+ // it as a deferred function.
267+ func DeleteEndpoint (t * testing.T , client * gophercloud.ServiceClient , endpointID string ) {
268+ err := endpoints .Delete (context .TODO (), client , endpointID ).ExtractErr ()
269+ if err != nil {
270+ t .Fatalf ("Unable to delete endpoint %s: %v" , endpointID , err )
271+ }
272+
273+ t .Logf ("Deleted endpoint: %s" , endpointID )
274+ }
275+
231276// DeleteProject will delete a project by ID. A fatal error will occur if
232277// the project ID failed to be deleted. This works best when using it as
233278// a deferred function.
0 commit comments