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 Query parameter to varset list options #877

Merged
merged 2 commits into from
Apr 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Add `Global` field to `RunTask`. by @glennsarti [#865](https://github.com/hashicorp/go-tfe/pull/865)
* Add `Stages` field to `WorkspaceRunTask`. by @glennsarti [#865](https://github.com/hashicorp/go-tfe/pull/865)
* Changing BETA `OrganizationScoped` attribute of `OAuthClient` to be a pointer for bug fix by @netramali [884](https://github.com/hashicorp/go-tfe/pull/884)
* Adds `Query` parameter to `VariableSetListOptions` to allow searching variable sets by name, by @JarrettSpiker[#877](https://github.com/hashicorp/go-tfe/pull/877)


## Deprecations
* The `Stage` field has been deprecated on `WorkspaceRunTask`. Instead, use `Stages`. by @glennsarti [#865](https://github.com/hashicorp/go-tfe/pull/865)
Expand Down
4 changes: 4 additions & 0 deletions variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const (
type VariableSetListOptions struct {
ListOptions
Include string `url:"include"`

// Optional: A query string used to filter variable sets.
// Any variable sets with a name partially matching this value will be returned.
Query string `url:"q,omitempty"`
}

// VariableSetCreateOptions represents the options for creating a new variable set within in a organization.
Expand Down
30 changes: 27 additions & 3 deletions variable_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ func TestVariableSetsList(t *testing.T) {
assert.Contains(t, vsl.Items, vsTest1)
assert.Contains(t, vsl.Items, vsTest2)

t.Skip("paging not supported yet in API")
assert.Equal(t, 1, vsl.CurrentPage)
assert.Equal(t, 2, vsl.TotalCount)
})

t.Run("with list options", func(t *testing.T) {
t.Skip("paging not supported yet in API")
// Request a page number which is out of range. The result should
// be successful, but return no results if the paging options are
// properly passed along.
Expand All @@ -57,6 +55,15 @@ func TestVariableSetsList(t *testing.T) {
assert.Nil(t, vsl)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})

t.Run("with query parameter", func(t *testing.T) {
vsl, err := client.VariableSets.List(ctx, orgTest.Name, &VariableSetListOptions{
Query: vsTest2.Name,
})
require.NoError(t, err)
assert.Len(t, vsl.Items, 1)
assert.Equal(t, vsTest2.ID, vsl.Items[0].ID)
})
}

func TestVariableSetsListForWorkspace(t *testing.T) {
Expand Down Expand Up @@ -88,7 +95,6 @@ func TestVariableSetsListForWorkspace(t *testing.T) {
})

t.Run("with list options", func(t *testing.T) {
t.Skip("paging not supported yet in API")
// Request a page number which is out of range. The result should
// be successful, but return no results if the paging options are
// properly passed along.
Expand All @@ -109,6 +115,15 @@ func TestVariableSetsListForWorkspace(t *testing.T) {
assert.Nil(t, vsl)
assert.EqualError(t, err, ErrInvalidWorkspaceID.Error())
})

t.Run("with query parameter", func(t *testing.T) {
vsl, err := client.VariableSets.List(ctx, orgTest.Name, &VariableSetListOptions{
Query: vsTest2.Name,
})
require.NoError(t, err)
assert.Len(t, vsl.Items, 1)
assert.Equal(t, vsTest2.ID, vsl.Items[0].ID)
})
}

func TestVariableSetsListForProject(t *testing.T) {
Expand Down Expand Up @@ -157,6 +172,15 @@ func TestVariableSetsListForProject(t *testing.T) {
assert.Nil(t, vsl)
assert.EqualError(t, err, ErrInvalidProjectID.Error())
})

t.Run("with query parameter", func(t *testing.T) {
vsl, err := client.VariableSets.List(ctx, orgTest.Name, &VariableSetListOptions{
Query: vsTest2.Name,
})
require.NoError(t, err)
assert.Len(t, vsl.Items, 1)
assert.Equal(t, vsTest2.ID, vsl.Items[0].ID)
})
}

func TestVariableSetsCreate(t *testing.T) {
Expand Down