Skip to content

Commit

Permalink
Merge pull request #438 from hashicorp/uk1288-add-exclude-tags-to-wor…
Browse files Browse the repository at this point in the history
…kspace-list-options

add exclude tags to workspace list options
  • Loading branch information
Uk1288 committed Jun 29, 2022
2 parents b30e3d8 + 5ff2232 commit efab77c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions workspace.go
Expand Up @@ -240,6 +240,9 @@ type WorkspaceListOptions struct {
// Optional: A search string (comma-separated tag names) used to filter the results.
Tags string `url:"search[tags],omitempty"`

// Optional: A search string (comma-separated tag names to exclude) used to filter the results.
ExcludeTags string `url:"search[exclude-tags],omitempty"`

// Optional: A list of relations to include. See available resources https://www.terraform.io/docs/cloud/api/workspaces.html#available-related-resources
Include []WSIncludeOpt `url:"include,omitempty"`
}
Expand Down
22 changes: 22 additions & 0 deletions workspace_integration_test.go
Expand Up @@ -94,6 +94,28 @@ func TestWorkspacesList(t *testing.T) {
assert.Equal(t, 1, wl.TotalCount)
})

t.Run("when searching using exclude-tags", func(t *testing.T) {
for wsID, tag := range map[string]string{wTest1.ID: "foo", wTest2.ID: "bar"} {
err := client.Workspaces.AddTags(ctx, wsID, WorkspaceAddTagsOptions{
Tags: []*Tag{
{
Name: tag,
},
},
})
require.NoError(t, err)
}

wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{
ExcludeTags: "foo",
})

require.NoError(t, err)
assert.Contains(t, wl.Items[0].ID, wTest2.ID)
assert.Equal(t, 1, wl.CurrentPage)
assert.Equal(t, 1, wl.TotalCount)
})

t.Run("when searching an unknown workspace", func(t *testing.T) {
// Use a nonexisting workspace name as search attribute. The result
// should be successful, but return no results.
Expand Down

0 comments on commit efab77c

Please sign in to comment.