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