Skip to content

Commit a8272c4

Browse files
committed
add project id option to workspace listing
1 parent 89e7909 commit a8272c4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

workspace.go

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ type WorkspaceListOptions struct {
263263
// Optional: A search on substring matching to filter the results.
264264
WildcardName string `url:"search[wildcard-name],omitempty"`
265265

266+
// Optional: A filter string to list all the workspaces linked to a given project id in the organization.
267+
ProjectId string `url:"filter[project][id],omitempty"`
268+
266269
// Optional: A list of relations to include. See available resources https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces#available-related-resources
267270
Include []WSIncludeOpt `url:"include,omitempty"`
268271
}

workspace_integration_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ func TestWorkspacesList(t *testing.T) {
217217
assert.NotEmpty(t, wTest.ID)
218218
assert.Equal(t, 0, wl.TotalCount)
219219
})
220+
221+
t.Run("when filtering using project id", func(t *testing.T) {
222+
p, pTestCleanup := createProject(t, client, orgTest)
223+
defer pTestCleanup()
224+
225+
// create a workspace with project
226+
w, wTestCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
227+
Name: String(randomString(t)),
228+
Project: p,
229+
})
230+
defer wTestCleanup()
231+
// Request a page number which is out of range. The result should
232+
// be successful, but return no results if the paging options are
233+
// properly passed along.
234+
wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{
235+
ProjectId: p.ID,
236+
})
237+
require.NoError(t, err)
238+
assert.Contains(t, wl.Items, w)
239+
})
220240
}
221241

222242
func TestWorkspacesCreateTableDriven(t *testing.T) {

0 commit comments

Comments
 (0)