Skip to content

Commit bb3dc7b

Browse files
committed
prep work for PPRV GA
1 parent 6e8965c commit bb3dc7b

3 files changed

+87
-169
lines changed

policy_set.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,14 @@ type PolicySet struct {
9393
Global bool `jsonapi:"attr,global"`
9494
PoliciesPath string `jsonapi:"attr,policies-path"`
9595
// **Note: This field is still in BETA and subject to change.**
96-
PolicyCount int `jsonapi:"attr,policy-count"`
97-
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
98-
WorkspaceCount int `jsonapi:"attr,workspace-count"`
99-
ProjectCount int `jsonapi:"attr,project-count"`
100-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
101-
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
102-
// **Note: This field is still in BETA and subject to change.**
103-
AgentEnabled bool `jsonapi:"attr,agent-enabled"`
104-
// **Note: This field is still in BETA and subject to change.**
105-
PolicyToolVersion string `jsonapi:"attr,policy-tool-version"`
96+
PolicyCount int `jsonapi:"attr,policy-count"`
97+
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
98+
WorkspaceCount int `jsonapi:"attr,workspace-count"`
99+
ProjectCount int `jsonapi:"attr,project-count"`
100+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
101+
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
102+
AgentEnabled bool `jsonapi:"attr,agent-enabled"`
103+
PolicyToolVersion string `jsonapi:"attr,policy-tool-version"`
106104

107105
// Relations
108106
// The organization to which the policy set belongs to.
@@ -184,11 +182,9 @@ type PolicySetCreateOptions struct {
184182
// Optional: Whether or not users can override this policy when it fails during a run. Only valid for policy evaluations.
185183
Overridable *bool `jsonapi:"attr,overridable,omitempty"`
186184

187-
// **Note: This field is still in BETA and subject to change.**
188185
// Optional: Whether or not the policy is run as an evaluation inside the agent.
189186
AgentEnabled bool `jsonapi:"attr,agent-enabled"`
190187

191-
// **Note: This field is still in BETA and subject to change.**
192188
// Optional: The policy tool version to run the evaluation against.
193189
PolicyToolVersion string `jsonapi:"attr,policy-tool-version,omitempty"`
194190

@@ -234,15 +230,12 @@ type PolicySetUpdateOptions struct {
234230
// Optional: Whether or not the policy set is global.
235231
Global *bool `jsonapi:"attr,global,omitempty"`
236232

237-
// **Note: This field is still in BETA and subject to change.**
238233
// Optional: Whether or not users can override this policy when it fails during a run. Only valid for policy evaluations.
239234
Overridable *bool `jsonapi:"attr,overridable,omitempty"`
240235

241-
// **Note: This field is still in BETA and subject to change.**
242236
// Optional: Whether or not the policy is run as an evaluation inside the agent.
243237
AgentEnabled bool `jsonapi:"attr,agent-enabled"`
244238

245-
// **Note: This field is still in BETA and subject to change.**
246239
// Optional: The policy tool version to run the evaluation against.
247240
PolicyToolVersion string `jsonapi:"attr,policy-tool-version"`
248241

policy_set_integration_beta_test.go

-148
This file was deleted.

policy_set_integration_test.go

+79-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ func TestPolicySetsList(t *testing.T) {
2929
excludedWorkspace, excludedWorkspaceCleanup := createWorkspace(t, client, orgTest)
3030
defer excludedWorkspaceCleanup()
3131

32-
psTest1, psTestCleanup1 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, nil, "")
32+
options := PolicySetCreateOptions{
33+
Kind: Sentinel,
34+
AgentEnabled: true,
35+
PolicyToolVersion: "0.22.1",
36+
Overridable: Bool(true),
37+
}
38+
39+
psTest1, psTestCleanup1 := createPolicySetWithOptions(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, options)
3340
defer psTestCleanup1()
34-
psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, nil, "")
41+
psTest2, psTestCleanup2 := createPolicySetWithOptions(t, client, orgTest, nil, []*Workspace{workspace}, []*Workspace{excludedWorkspace}, options)
3542
defer psTestCleanup2()
3643
psTest3, psTestCleanup3 := createPolicySet(t, client, orgTest, nil, []*Workspace{workspace}, nil, OPA)
3744
defer psTestCleanup3()
@@ -43,6 +50,8 @@ func TestPolicySetsList(t *testing.T) {
4350
assert.Contains(t, psl.Items, psTest1)
4451
assert.Contains(t, psl.Items, psTest2)
4552
assert.Contains(t, psl.Items, psTest3)
53+
assert.Equal(t, true, psl.Items[0].AgentEnabled)
54+
assert.Equal(t, "0.22.1", psl.Items[0].PolicyToolVersion)
4655
assert.Equal(t, 1, psl.CurrentPage)
4756
assert.Equal(t, 3, psl.TotalCount)
4857
})
@@ -151,6 +160,43 @@ func TestPolicySetsCreate(t *testing.T) {
151160
assert.False(t, ps.Global)
152161
})
153162

163+
t.Run("with pinned policy runtime version valid attributes", func(t *testing.T) {
164+
options := PolicySetCreateOptions{
165+
Name: String("policy-set"),
166+
Kind: Sentinel,
167+
AgentEnabled: true,
168+
PolicyToolVersion: "0.22.1",
169+
}
170+
171+
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
172+
require.NoError(t, err)
173+
174+
assert.Equal(t, ps.Name, *options.Name)
175+
assert.Equal(t, ps.Description, "")
176+
assert.Equal(t, ps.Kind, Sentinel)
177+
assert.Equal(t, ps.AgentEnabled, true)
178+
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
179+
assert.False(t, ps.Global)
180+
})
181+
182+
t.Run("with pinned policy runtime version and missing kind", func(t *testing.T) {
183+
options := PolicySetCreateOptions{
184+
Name: String(randomString(t)),
185+
AgentEnabled: true,
186+
PolicyToolVersion: "0.22.1",
187+
Overridable: Bool(true),
188+
}
189+
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
190+
require.NoError(t, err)
191+
192+
assert.Equal(t, ps.Name, *options.Name)
193+
assert.Equal(t, ps.Description, "")
194+
assert.Equal(t, ps.Kind, Sentinel)
195+
assert.Equal(t, ps.AgentEnabled, true)
196+
assert.Equal(t, ps.PolicyToolVersion, "0.22.1")
197+
assert.False(t, ps.Global)
198+
})
199+
154200
t.Run("with kind missing", func(t *testing.T) {
155201
options := PolicySetCreateOptions{
156202
Name: String("policy-set1"),
@@ -165,6 +211,22 @@ func TestPolicySetsCreate(t *testing.T) {
165211
assert.False(t, ps.Global)
166212
})
167213

214+
t.Run("with agent enabled missing", func(t *testing.T) {
215+
options := PolicySetCreateOptions{
216+
Name: String(randomString(t)),
217+
Kind: Sentinel,
218+
}
219+
220+
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
221+
require.NoError(t, err)
222+
223+
assert.Equal(t, ps.Name, *options.Name)
224+
assert.Equal(t, ps.Description, "")
225+
assert.Equal(t, ps.Kind, Sentinel)
226+
assert.Equal(t, ps.AgentEnabled, false)
227+
assert.False(t, ps.Global)
228+
})
229+
168230
t.Run("with all attributes provided - sentinel", func(t *testing.T) {
169231
options := PolicySetCreateOptions{
170232
Name: String("global"),
@@ -565,21 +627,32 @@ func TestPolicySetsUpdate(t *testing.T) {
565627

566628
upgradeOrganizationSubscription(t, client, orgTest)
567629

568-
psTest, psTestCleanup := createPolicySet(t, client, orgTest, nil, nil, nil, nil, "")
630+
options := PolicySetCreateOptions{
631+
Kind: Sentinel,
632+
AgentEnabled: true,
633+
PolicyToolVersion: "0.22.1",
634+
Overridable: Bool(true),
635+
}
636+
637+
psTest, psTestCleanup := createPolicySetWithOptions(t, client, orgTest, nil, nil, options)
569638
defer psTestCleanup()
570639
psTest2, psTestCleanup2 := createPolicySet(t, client, orgTest, nil, nil, nil, "opa")
571640
defer psTestCleanup2()
572641

573642
t.Run("with valid attributes", func(t *testing.T) {
574643
options := PolicySetUpdateOptions{
575-
Name: String("global"),
576-
Description: String("Policies in this set will be checked in ALL workspaces!"),
577-
Global: Bool(true),
644+
AgentEnabled: false,
645+
Name: String("global"),
646+
Description: String("Policies in this set will be checked in ALL workspaces!"),
647+
Global: Bool(true),
578648
}
579649

580650
ps, err := client.PolicySets.Update(ctx, psTest.ID, options)
581651
require.NoError(t, err)
582652

653+
assert.Equal(t, ps.AgentEnabled, false)
654+
assert.Equal(t, ps.PolicyToolVersion, "")
655+
assert.Nil(t, ps.Overridable)
583656
assert.Equal(t, ps.Name, *options.Name)
584657
assert.Equal(t, ps.Description, *options.Description)
585658
assert.True(t, ps.Global)

0 commit comments

Comments
 (0)