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 search[wildcard-name] to WorkspaceListOptions #569

Merged
merged 1 commit into from Nov 2, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
# Unreleased

* Add `search[wildcard-name]` to `WorkspaceListOptions` by @laurenolivia [#569](https://github.com/hashicorp/go-tfe/pull/569)

## Enhancements

* Add `NotificationTriggerAssessmentCheckFailed` notification trigger type by @rexredinger [#549](https://github.com/hashicorp/go-tfe/pull/549)
Expand Down
3 changes: 3 additions & 0 deletions workspace.go
Expand Up @@ -252,6 +252,9 @@ type WorkspaceListOptions struct {
// Optional: A search string (comma-separated tag names to exclude) used to filter the results.
ExcludeTags string `url:"search[exclude-tags],omitempty"`

// Optional: A search on substring matching to filter the results.
WildcardName string `url:"search[wildcard-name],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
36 changes: 35 additions & 1 deletion workspace_integration_test.go
Expand Up @@ -184,6 +184,40 @@ func TestWorkspacesList(t *testing.T) {

assert.True(t, foundWTest1)
})

t.Run("when searching a known substring", func(t *testing.T) {
wildcardSearch := "*-prod"
// should be successful, and return 1 result
wTest, wTestCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
Name: String("hashicorp-prod"),
})
t.Cleanup(wTestCleanup)

wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{
WildcardName: wildcardSearch,
})

require.NoError(t, err)
assert.NotEmpty(t, wTest.ID)
assert.Equal(t, 1, wl.TotalCount)
})

t.Run("when wildcard match does not exist", func(t *testing.T) {
wildcardSearch := "*-dev"
// should be successful, but return no results
wTest, wTestCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
Name: String("hashicorp-staging"),
})
t.Cleanup(wTestCleanup)

wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{
WildcardName: wildcardSearch,
})

require.NoError(t, err)
assert.NotEmpty(t, wTest.ID)
assert.Equal(t, 0, wl.TotalCount)
})
}

func TestWorkspacesCreateTableDriven(t *testing.T) {
Expand Down Expand Up @@ -816,7 +850,7 @@ func TestWorkspacesUpdate(t *testing.T) {
assert.Equal(t, err, ErrUnsupportedOperations)
})

t.Run("when 'agent' execution mode is specified without an an agent pool ID", func(t *testing.T) {
t.Run("when 'agent' execution mode is specified without an agent pool ID", func(t *testing.T) {
options := WorkspaceUpdateOptions{
ExecutionMode: String("agent"),
}
Expand Down