Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeb committed Apr 17, 2024
1 parent fd9e4e1 commit 181d77d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
20 changes: 20 additions & 0 deletions internal/acceptance/openstack/identity/v3/projects_test.go
Expand Up @@ -365,3 +365,23 @@ func TestProjectsTags(t *testing.T) {
tools.PrintResource(t, updatedProject)
th.AssertEquals(t, len(updatedProject.Tags), 0)
}

func TestTagCRUD(t *testing.T) {
clients.RequireAdmin(t)

client, err := clients.NewIdentityV3Client()
th.AssertNoErr(t, err)

projectMain, err := CreateProject(t, client, nil)
th.AssertNoErr(t, err)
defer DeleteProject(t, client, projectMain.ID)

err = projects.AddTag(context.TODO(), client, projectMain.ID, "Tag1").ExtractErr()
th.AssertNoErr(t, err)

err = projects.CheckTag(context.TODO(), client, projectMain.ID, "Tag1").ExtractErr()
th.AssertNoErr(t, err)

err = projects.DeleteTag(context.TODO(), client, projectMain.ID, "Tag1").ExtractErr()
th.AssertNoErr(t, err)
}
6 changes: 3 additions & 3 deletions openstack/identity/v3/projects/doc.go
Expand Up @@ -69,7 +69,7 @@ Example to Check if a Project contains a Tag
projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag:= "atag"
err := projects.GetProjectTag(context.TODO(), identityClient, projectID,tag).ExtractErr()
err := projects.CheckTag(context.TODO(), identityClient, projectID, tag).ExtractErr()
if err != nil {
panic(err)
}
Expand All @@ -78,7 +78,7 @@ Example to Add a Tag to a project
projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag:= "atag"
err := projects.AddProjectTag(context.TODO(), identityClient, projectID,tag).ExtractErr()
err := projects.AddProjectTag(context.TODO(), identityClient, projectID, tag).ExtractErr()
if err != nil {
panic(err)
}
Expand All @@ -87,7 +87,7 @@ Example to Delete a Project Tag
projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag:= "atag"
err := projects.DeleteProjectTag(context.TODO(), identityClient, projectID,tag).ExtractErr()
err := projects.DeleteProjectTag(context.TODO(), identityClient, projectID, tag).ExtractErr()
if err != nil {
panic(err)
}
Expand Down
12 changes: 6 additions & 6 deletions openstack/identity/v3/projects/requests.go
Expand Up @@ -244,26 +244,26 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, o
return
}

// GetProjectTag checks if a a tag exists in a project.
func GetProjectTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r GetProjectTagResult) {
// CheckTag checks if a a tag exists in a project.
func CheckTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r GetProjectTagResult) {
resp, err := client.Get(ctx, getProjectTagURL(client, projectID, tag), nil, &gophercloud.RequestOpts{
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// AddProjectTag adds a tag in a project.
func AddProjectTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r AddProjectTagResult) {
// AddTag adds a tag to a project.
func AddTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r AddProjectTagResult) {
resp, err := client.Put(ctx, addProjectTagURL(client, projectID, tag), nil, nil, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// DeleteProjectTag deletes a tag from a project.
func DeleteProjectTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r DeleteProjectTagResult) {
// DeleteTag deletes a tag from a project.
func DeleteTag(ctx context.Context, client *gophercloud.ServiceClient, projectID string, tag string) (r DeleteProjectTagResult) {
resp, err := client.Delete(ctx, deleteProjectTagURL(client, projectID, tag), &gophercloud.RequestOpts{
OkCodes: []int{204},
})
Expand Down
12 changes: 6 additions & 6 deletions openstack/identity/v3/projects/testing/requests_test.go
Expand Up @@ -136,35 +136,35 @@ func TestUpdateProject(t *testing.T) {
th.CheckDeepEquals(t, UpdatedRedTeam, *actual)
}

func TestGetProjectTag(t *testing.T) {
func TestCheckTag(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCheckProjectTagSuccessfully(t)

projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag := "atag"
res := projects.GetProjectTag(context.TODO(), client.ServiceClient(), projectID, tag)
res := projects.CheckTag(context.TODO(), client.ServiceClient(), projectID, tag)
th.AssertNoErr(t, res.Err)
}

func TestAddProjectTag(t *testing.T) {
func TestAddPTag(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleAddProjectTagSuccessfully(t)

projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag := "atag"
res := projects.AddProjectTag(context.TODO(), client.ServiceClient(), projectID, tag)
res := projects.AddTag(context.TODO(), client.ServiceClient(), projectID, tag)
th.AssertNoErr(t, res.Err)
}

func TestDeleteProjectTag(t *testing.T) {
func TestDeleteTag(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleDeleteProjectTagSuccessfully(t)

projectID := "966b3c7d36a24facaf20b7e458bf2192"
tag := "atag"
res := projects.DeleteProjectTag(context.TODO(), client.ServiceClient(), projectID, tag)
res := projects.DeleteTag(context.TODO(), client.ServiceClient(), projectID, tag)
th.AssertNoErr(t, res.Err)
}

0 comments on commit 181d77d

Please sign in to comment.