Skip to content

Commit

Permalink
Merge pull request #877 from hashicorp/jspiker/varsetSearch
Browse files Browse the repository at this point in the history
Add Query parameter to varset list options
  • Loading branch information
JarrettSpiker committed Apr 16, 2024
2 parents 50939d7 + a8fddbc commit a853981
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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

0 comments on commit a853981

Please sign in to comment.