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 Include param to policyset list #497

Merged
merged 3 commits into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Adds additional Task Stage and Run Statuses for Pre-plan run tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469)
* Adds `stage` field to the create and update methods for Workspace Run Tasks by @glennsarti [#469](https://github.com/hashicorp/go-tfe/pull/469)
* Adds `ResourcesProcessed`, `StateVersion`, `TerraformVersion`, `Modules`, `Providers`, and `Resources` fields to the State Version struct by @laurenolivia [#484](https://github.com/hashicorp/go-tfe/pull/484)
* Add `Include` param field to `PolicySetListOptions` to allow policy list to include related resource data such as workspaces, policies, newest_version, or current_version by @Uk1288 [#497](https://github.com/hashicorp/go-tfe/pull/497)

# v1.6.0

Expand Down
4 changes: 4 additions & 0 deletions policy_set.go
Expand Up @@ -104,6 +104,10 @@ type PolicySetListOptions struct {

// Optional: A search string (partial policy set name) used to filter the results.
Search string `url:"search[name],omitempty"`

// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/policy-sets#available-related-resources
Include []PolicySetIncludeOpt `url:"include,omitempty"`
}

// PolicySetReadOptions are read options.
Expand Down
39 changes: 37 additions & 2 deletions policy_set_integration_test.go
Expand Up @@ -23,9 +23,14 @@ func TestPolicySetsList(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

psTest1, psTestCleanup1 := createPolicySet(t, client, orgTest, nil, nil)
upgradeOrganizationSubscription(t, client, orgTest)

workspace, workspaceCleanup := createWorkspace(t, client, orgTest)
defer workspaceCleanup()

psTest1, psTestCleanup1 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace})
defer psTestCleanup1()
psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, nil)
psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace})
defer psTestCleanup2()

t.Run("without list options", func(t *testing.T) {
Expand Down Expand Up @@ -69,6 +74,19 @@ func TestPolicySetsList(t *testing.T) {
assert.Equal(t, 1, psl.TotalCount)
})

t.Run("with include param", func(t *testing.T) {
psl, err := client.PolicySets.List(ctx, orgTest.Name, &PolicySetListOptions{
Include: []PolicySetIncludeOpt{PolicySetWorkspaces},
})
require.NoError(t, err)

assert.Equal(t, 2, len(psl.Items))

assert.NotNil(t, psl.Items[0].Workspaces)
assert.Equal(t, 1, len(psl.Items[0].Workspaces))
assert.Equal(t, workspace.ID, psl.Items[0].Workspaces[0].ID)
})

t.Run("without a valid organization", func(t *testing.T) {
ps, err := client.PolicySets.List(ctx, badIdentifier, nil)
assert.Nil(t, ps)
Expand All @@ -84,6 +102,9 @@ func TestPolicySetsCreate(t *testing.T) {

orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

var vcsPolicyID string

t.Run("with valid attributes", func(t *testing.T) {
Expand Down Expand Up @@ -245,6 +266,8 @@ func TestPolicySetsRead(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil)
defer psTestCleanup()

Expand Down Expand Up @@ -311,6 +334,8 @@ func TestPolicySetsUpdate(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil)
defer psTestCleanup()

Expand Down Expand Up @@ -355,6 +380,8 @@ func TestPolicySetsAddPolicies(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

pTest1, pTestCleanup1 := createPolicy(t, client, orgTest)
defer pTestCleanup1()
pTest2, pTestCleanup2 := createPolicy(t, client, orgTest)
Expand Down Expand Up @@ -410,6 +437,8 @@ func TestPolicySetsRemovePolicies(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

pTest1, pTestCleanup1 := createPolicy(t, client, orgTest)
defer pTestCleanup1()
pTest2, pTestCleanup2 := createPolicy(t, client, orgTest)
Expand Down Expand Up @@ -459,6 +488,8 @@ func TestPolicySetsAddWorkspaces(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

wTest1, wTestCleanup1 := createWorkspace(t, client, orgTest)
defer wTestCleanup1()
wTest2, wTestCleanup2 := createWorkspace(t, client, orgTest)
Expand Down Expand Up @@ -528,6 +559,8 @@ func TestPolicySetsRemoveWorkspaces(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

wTest1, wTestCleanup1 := createWorkspace(t, client, orgTest)
defer wTestCleanup1()
wTest2, wTestCleanup2 := createWorkspace(t, client, orgTest)
Expand Down Expand Up @@ -591,6 +624,8 @@ func TestPolicySetsDelete(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

upgradeOrganizationSubscription(t, client, orgTest)

psTest, _ := createPolicySet(t, client, orgTest, nil, nil)

t.Run("with valid options", func(t *testing.T) {
Expand Down