Skip to content

Commit 5ff2232

Browse files
committed
add exclude tags to workspace list options
1 parent cc5d816 commit 5ff2232

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

workspace.go

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ type WorkspaceListOptions struct {
240240
// Optional: A search string (comma-separated tag names) used to filter the results.
241241
Tags string `url:"search[tags],omitempty"`
242242

243+
// Optional: A search string (comma-separated tag names to exclude) used to filter the results.
244+
ExcludeTags string `url:"search[exclude-tags],omitempty"`
245+
243246
// Optional: A list of relations to include. See available resources https://www.terraform.io/docs/cloud/api/workspaces.html#available-related-resources
244247
Include []WSIncludeOpt `url:"include,omitempty"`
245248
}

workspace_integration_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ func TestWorkspacesList(t *testing.T) {
9494
assert.Equal(t, 1, wl.TotalCount)
9595
})
9696

97+
t.Run("when searching using exclude-tags", func(t *testing.T) {
98+
for wsID, tag := range map[string]string{wTest1.ID: "foo", wTest2.ID: "bar"} {
99+
err := client.Workspaces.AddTags(ctx, wsID, WorkspaceAddTagsOptions{
100+
Tags: []*Tag{
101+
{
102+
Name: tag,
103+
},
104+
},
105+
})
106+
require.NoError(t, err)
107+
}
108+
109+
wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{
110+
ExcludeTags: "foo",
111+
})
112+
113+
require.NoError(t, err)
114+
assert.Contains(t, wl.Items[0].ID, wTest2.ID)
115+
assert.Equal(t, 1, wl.CurrentPage)
116+
assert.Equal(t, 1, wl.TotalCount)
117+
})
118+
97119
t.Run("when searching an unknown workspace", func(t *testing.T) {
98120
// Use a nonexisting workspace name as search attribute. The result
99121
// should be successful, but return no results.

0 commit comments

Comments
 (0)