Skip to content

Commit

Permalink
add policy set test with include param
Browse files Browse the repository at this point in the history
  • Loading branch information
Uk1288 committed Aug 10, 2022
1 parent 4510c80 commit 7faaf12
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
5 changes: 0 additions & 5 deletions CHANGELOG.md
Expand Up @@ -5,13 +5,8 @@
* Adds new run creation attributes: `allow-empty-apply`, `terraform-version`, `plan-only` by @sebasslash [#482](https://github.com/hashicorp/go-tfe/pull/447)
* 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)
<<<<<<< HEAD
* 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 [#471](https://github.com/hashicorp/go-tfe/pull/471)
=======
* 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 [#494](https://github.com/hashicorp/go-tfe/pull/494)
>>>>>>> 65d8fda (Update changelog)
# v1.6.0

## Enhancements
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

0 comments on commit 7faaf12

Please sign in to comment.