@@ -24,6 +24,20 @@ func TestPolicySetsList(t *testing.T) {
24
24
25
25
upgradeOrganizationSubscription (t , client , orgTest )
26
26
27
+ version := createAdminSentinelVersion ()
28
+ opts := AdminSentinelVersionCreateOptions {
29
+ Version : version ,
30
+ URL : "https://www.hashicorp.com" ,
31
+ SHA : genSha (t ),
32
+ Official : Bool (false ),
33
+ Deprecated : Bool (false ),
34
+ DeprecatedReason : String ("Test Reason" ),
35
+ Enabled : Bool (true ),
36
+ Beta : Bool (false ),
37
+ }
38
+ sv , err := client .Admin .SentinelVersions .Create (ctx , opts )
39
+ require .NoError (t , err )
40
+
27
41
workspace , workspaceCleanup := createWorkspace (t , client , orgTest )
28
42
defer workspaceCleanup ()
29
43
excludedWorkspace , excludedWorkspaceCleanup := createWorkspace (t , client , orgTest )
@@ -32,7 +46,7 @@ func TestPolicySetsList(t *testing.T) {
32
46
options := PolicySetCreateOptions {
33
47
Kind : Sentinel ,
34
48
AgentEnabled : true ,
35
- PolicyToolVersion : "0.22.1" ,
49
+ PolicyToolVersion : sv . Version ,
36
50
Overridable : Bool (true ),
37
51
}
38
52
@@ -42,6 +56,10 @@ func TestPolicySetsList(t *testing.T) {
42
56
defer psTestCleanup2 ()
43
57
psTest3 , psTestCleanup3 := createPolicySet (t , client , orgTest , nil , []* Workspace {workspace }, []* Workspace {excludedWorkspace }, nil , OPA )
44
58
defer psTestCleanup3 ()
59
+ defer func () {
60
+ err := client .Admin .SentinelVersions .Delete (ctx , sv .ID )
61
+ require .NoError (t , err )
62
+ }()
45
63
46
64
t .Run ("without list options" , func (t * testing.T ) {
47
65
psl , err := client .PolicySets .List (ctx , orgTest .Name , nil )
@@ -51,7 +69,6 @@ func TestPolicySetsList(t *testing.T) {
51
69
assert .Contains (t , psl .Items , psTest2 )
52
70
assert .Contains (t , psl .Items , psTest3 )
53
71
assert .Equal (t , true , psl .Items [0 ].AgentEnabled )
54
- assert .Equal (t , "0.22.1" , psl .Items [0 ].PolicyToolVersion )
55
72
assert .Equal (t , 1 , psl .CurrentPage )
56
73
assert .Equal (t , 3 , psl .TotalCount )
57
74
})
@@ -130,11 +147,30 @@ func TestPolicySetsCreate(t *testing.T) {
130
147
131
148
upgradeOrganizationSubscription (t , client , orgTest )
132
149
150
+ version := createAdminSentinelVersion ()
151
+ opts := AdminSentinelVersionCreateOptions {
152
+ Version : version ,
153
+ URL : "https://www.hashicorp.com" ,
154
+ SHA : genSha (t ),
155
+ Official : Bool (false ),
156
+ Deprecated : Bool (false ),
157
+ DeprecatedReason : String ("Test Reason" ),
158
+ Enabled : Bool (true ),
159
+ Beta : Bool (false ),
160
+ }
161
+ sv , err := client .Admin .SentinelVersions .Create (ctx , opts )
162
+ defer func () {
163
+ err := client .Admin .SentinelVersions .Delete (ctx , sv .ID )
164
+ require .NoError (t , err )
165
+ }()
166
+ require .NoError (t , err )
167
+
133
168
var vcsPolicyID string
134
169
135
170
t .Run ("with valid attributes" , func (t * testing.T ) {
136
171
options := PolicySetCreateOptions {
137
- Name : String ("policy-set" ),
172
+ Name : String (randomString (t )),
173
+ PolicyToolVersion : sv .Version ,
138
174
}
139
175
140
176
ps , err := client .PolicySets .Create (ctx , orgTest .Name , options )
@@ -162,10 +198,10 @@ func TestPolicySetsCreate(t *testing.T) {
162
198
163
199
t .Run ("with pinned policy runtime version valid attributes" , func (t * testing.T ) {
164
200
options := PolicySetCreateOptions {
165
- Name : String ("policy-set" ),
201
+ Name : String (randomString ( t ) ),
166
202
Kind : Sentinel ,
167
203
AgentEnabled : true ,
168
- PolicyToolVersion : "0.22.1" ,
204
+ PolicyToolVersion : sv . Version ,
169
205
}
170
206
171
207
ps , err := client .PolicySets .Create (ctx , orgTest .Name , options )
@@ -175,15 +211,15 @@ func TestPolicySetsCreate(t *testing.T) {
175
211
assert .Equal (t , ps .Description , "" )
176
212
assert .Equal (t , ps .Kind , Sentinel )
177
213
assert .Equal (t , ps .AgentEnabled , true )
178
- assert .Equal (t , ps .PolicyToolVersion , "0.22.1" )
214
+ assert .Equal (t , ps .PolicyToolVersion , sv . Version )
179
215
assert .False (t , ps .Global )
180
216
})
181
217
182
218
t .Run ("with pinned policy runtime version and missing kind" , func (t * testing.T ) {
183
219
options := PolicySetCreateOptions {
184
220
Name : String (randomString (t )),
185
221
AgentEnabled : true ,
186
- PolicyToolVersion : "0.22.1" ,
222
+ PolicyToolVersion : sv . Version ,
187
223
Overridable : Bool (true ),
188
224
}
189
225
ps , err := client .PolicySets .Create (ctx , orgTest .Name , options )
@@ -193,7 +229,7 @@ func TestPolicySetsCreate(t *testing.T) {
193
229
assert .Equal (t , ps .Description , "" )
194
230
assert .Equal (t , ps .Kind , Sentinel )
195
231
assert .Equal (t , ps .AgentEnabled , true )
196
- assert .Equal (t , ps .PolicyToolVersion , "0.22.1" )
232
+ assert .Equal (t , ps .PolicyToolVersion , sv . Version )
197
233
assert .False (t , ps .Global )
198
234
})
199
235
@@ -627,10 +663,28 @@ func TestPolicySetsUpdate(t *testing.T) {
627
663
628
664
upgradeOrganizationSubscription (t , client , orgTest )
629
665
666
+ version := createAdminSentinelVersion ()
667
+ opts := AdminSentinelVersionCreateOptions {
668
+ Version : version ,
669
+ URL : "https://www.hashicorp.com" ,
670
+ SHA : genSha (t ),
671
+ Official : Bool (false ),
672
+ Deprecated : Bool (false ),
673
+ DeprecatedReason : String ("Test Reason" ),
674
+ Enabled : Bool (true ),
675
+ Beta : Bool (false ),
676
+ }
677
+ sv , err := client .Admin .SentinelVersions .Create (ctx , opts )
678
+ defer func () {
679
+ err := client .Admin .SentinelVersions .Delete (ctx , sv .ID )
680
+ require .NoError (t , err )
681
+ }()
682
+ require .NoError (t , err )
683
+
630
684
options := PolicySetCreateOptions {
631
685
Kind : Sentinel ,
632
686
AgentEnabled : true ,
633
- PolicyToolVersion : "0.22.1" ,
687
+ PolicyToolVersion : sv . Version ,
634
688
Overridable : Bool (true ),
635
689
}
636
690
0 commit comments