Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclude tags to workspace list options #438

Merged
merged 1 commit into from Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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