@@ -29,9 +29,16 @@ func TestPolicySetsList(t *testing.T) {
29
29
excludedWorkspace , excludedWorkspaceCleanup := createWorkspace (t , client , orgTest )
30
30
defer excludedWorkspaceCleanup ()
31
31
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 )
33
40
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 )
35
42
defer psTestCleanup2 ()
36
43
psTest3 , psTestCleanup3 := createPolicySet (t , client , orgTest , nil , []* Workspace {workspace }, nil , OPA )
37
44
defer psTestCleanup3 ()
@@ -43,6 +50,8 @@ func TestPolicySetsList(t *testing.T) {
43
50
assert .Contains (t , psl .Items , psTest1 )
44
51
assert .Contains (t , psl .Items , psTest2 )
45
52
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 )
46
55
assert .Equal (t , 1 , psl .CurrentPage )
47
56
assert .Equal (t , 3 , psl .TotalCount )
48
57
})
@@ -151,6 +160,43 @@ func TestPolicySetsCreate(t *testing.T) {
151
160
assert .False (t , ps .Global )
152
161
})
153
162
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
+
154
200
t .Run ("with kind missing" , func (t * testing.T ) {
155
201
options := PolicySetCreateOptions {
156
202
Name : String ("policy-set1" ),
@@ -165,6 +211,22 @@ func TestPolicySetsCreate(t *testing.T) {
165
211
assert .False (t , ps .Global )
166
212
})
167
213
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
+
168
230
t .Run ("with all attributes provided - sentinel" , func (t * testing.T ) {
169
231
options := PolicySetCreateOptions {
170
232
Name : String ("global" ),
@@ -565,21 +627,32 @@ func TestPolicySetsUpdate(t *testing.T) {
565
627
566
628
upgradeOrganizationSubscription (t , client , orgTest )
567
629
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 )
569
638
defer psTestCleanup ()
570
639
psTest2 , psTestCleanup2 := createPolicySet (t , client , orgTest , nil , nil , nil , "opa" )
571
640
defer psTestCleanup2 ()
572
641
573
642
t .Run ("with valid attributes" , func (t * testing.T ) {
574
643
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 ),
578
648
}
579
649
580
650
ps , err := client .PolicySets .Update (ctx , psTest .ID , options )
581
651
require .NoError (t , err )
582
652
653
+ assert .Equal (t , ps .AgentEnabled , false )
654
+ assert .Equal (t , ps .PolicyToolVersion , "" )
655
+ assert .Nil (t , ps .Overridable )
583
656
assert .Equal (t , ps .Name , * options .Name )
584
657
assert .Equal (t , ps .Description , * options .Description )
585
658
assert .True (t , ps .Global )
0 commit comments