Skip to content

Commit

Permalink
add kind for policy set creation + update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinalirao committed Nov 1, 2022
1 parent 6f68d40 commit f16efbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions policy_set.go
Expand Up @@ -10,6 +10,15 @@ import (
// Compile-time proof of interface implementation.
var _ PolicySets = (*policySets)(nil)

// PolicyKind is an indicator of the underlying technology that the policy or policy set supports.
// There are two Policykinds documented in the enum.
type PolicyKind string

const (
OPA PolicyKind = "opa"
Sentinel PolicyKind = "sentinel"
)

// PolicySets describes all the policy set related methods that the Terraform
// Enterprise API supports.
//
Expand Down Expand Up @@ -64,6 +73,7 @@ type PolicySet struct {
ID string `jsonapi:"primary,policy-sets"`
Name string `jsonapi:"attr,name"`
Description string `jsonapi:"attr,description"`
Kind string `jsonapi:"attr,kind"`
Global bool `jsonapi:"attr,global"`
PoliciesPath string `jsonapi:"attr,policies-path"`
PolicyCount int `jsonapi:"attr,policy-count"`
Expand Down Expand Up @@ -136,6 +146,9 @@ type PolicySetCreateOptions struct {
// Optional: Whether or not the policy set is global.
Global *bool `jsonapi:"attr,global,omitempty"`

// Optional: The underlying technology that the policy set supports
Kind PolicyKind `jsonapi:"attr,kind,omitempty"`

// Optional: The sub-path within the attached VCS repository to ingress. All
// files and directories outside of this sub-path will be ignored.
// This option may only be specified when a VCS repo is present.
Expand Down
22 changes: 22 additions & 0 deletions policy_set_integration_test.go
Expand Up @@ -112,20 +112,37 @@ func TestPolicySetsCreate(t *testing.T) {
t.Run("with valid attributes", func(t *testing.T) {
options := PolicySetCreateOptions{
Name: String("policy-set"),
Kind: OPA,
}

ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
require.NoError(t, err)

assert.Equal(t, ps.Name, *options.Name)
assert.Equal(t, ps.Description, "")
assert.Equal(t, ps.Kind, "opa")
assert.False(t, ps.Global)
})

t.Run("with kind missing", func(t *testing.T) {
options := PolicySetCreateOptions{
Name: String("policy-set2"),
}

ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
require.NoError(t, err)

assert.Equal(t, ps.Name, *options.Name)
assert.Equal(t, ps.Description, "")
assert.Equal(t, ps.Kind, "sentinel")
assert.False(t, ps.Global)
})

t.Run("with all attributes provided", func(t *testing.T) {
options := PolicySetCreateOptions{
Name: String("global"),
Description: String("Policies in this set will be checked in ALL workspaces!"),
Kind: Sentinel,
Global: Bool(true),
}

Expand All @@ -134,6 +151,7 @@ func TestPolicySetsCreate(t *testing.T) {

assert.Equal(t, ps.Name, *options.Name)
assert.Equal(t, ps.Description, *options.Description)
assert.Equal(t, ps.Kind, "sentinel")
assert.True(t, ps.Global)
})

Expand All @@ -146,6 +164,7 @@ func TestPolicySetsCreate(t *testing.T) {
options := PolicySetCreateOptions{
Name: String("populated-policy-set"),
Policies: []*Policy{pTest},
Kind: Sentinel,
Workspaces: []*Workspace{wTest},
}

Expand All @@ -156,6 +175,7 @@ func TestPolicySetsCreate(t *testing.T) {
assert.Equal(t, ps.PolicyCount, 1)
assert.Equal(t, ps.Policies[0].ID, pTest.ID)
assert.Equal(t, ps.WorkspaceCount, 1)
assert.Equal(t, ps.Kind, "sentinel")
assert.Equal(t, ps.Workspaces[0].ID, wTest.ID)
})

Expand All @@ -170,6 +190,7 @@ func TestPolicySetsCreate(t *testing.T) {

options := PolicySetCreateOptions{
Name: String("vcs-policy-set"),
Kind: Sentinel,
PoliciesPath: String("/policy-sets/foo"),
VCSRepo: &VCSRepoOptions{
Branch: String("policies"),
Expand All @@ -190,6 +211,7 @@ func TestPolicySetsCreate(t *testing.T) {
assert.False(t, ps.Global)
assert.Equal(t, ps.PoliciesPath, "/policy-sets/foo")
assert.Equal(t, ps.VCSRepo.Branch, "policies")
assert.Equal(t, ps.Kind, "sentinel")
assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.IngressSubmodules, true)
Expand Down

0 comments on commit f16efbb

Please sign in to comment.