@@ -102,7 +102,46 @@ func TestAdminOPAVersions_CreateDelete(t *testing.T) {
102
102
ctx := context .Background ()
103
103
version := createAdminOPAVersion ()
104
104
105
- t .Run ("with valid options" , func (t * testing.T ) {
105
+ t .Run ("with valid options including archs" , func (t * testing.T ) {
106
+ opts := AdminOPAVersionCreateOptions {
107
+ Version : version ,
108
+ Deprecated : Bool (true ),
109
+ DeprecatedReason : String ("Test Reason" ),
110
+ Official : Bool (false ),
111
+ Enabled : Bool (false ),
112
+ Beta : Bool (false ),
113
+ Archs : []* ToolVersionArchitecture {
114
+ {
115
+ URL : "https://www.hashicorp.com" ,
116
+ Sha : * String (genSha (t )),
117
+ OS : linux ,
118
+ Arch : amd64 ,
119
+ },
120
+ {
121
+ URL : "https://www.hashicorp.com" ,
122
+ Sha : * String (genSha (t )),
123
+ OS : linux ,
124
+ Arch : arm64 ,
125
+ }},
126
+ }
127
+ ov , err := client .Admin .OPAVersions .Create (ctx , opts )
128
+ require .NoError (t , err )
129
+
130
+ defer func () {
131
+ deleteErr := client .Admin .OPAVersions .Delete (ctx , ov .ID )
132
+ require .NoError (t , deleteErr )
133
+ }()
134
+
135
+ assert .Equal (t , opts .Version , ov .Version )
136
+ assert .ElementsMatch (t , opts .Archs , ov .Archs )
137
+ assert .Equal (t , * opts .Official , ov .Official )
138
+ assert .Equal (t , * opts .Deprecated , ov .Deprecated )
139
+ assert .Equal (t , * opts .DeprecatedReason , * ov .DeprecatedReason )
140
+ assert .Equal (t , * opts .Enabled , ov .Enabled )
141
+ assert .Equal (t , * opts .Beta , ov .Beta )
142
+ })
143
+
144
+ t .Run ("with valid options including, url, and sha" , func (t * testing.T ) {
106
145
opts := AdminOPAVersionCreateOptions {
107
146
Version : version ,
108
147
URL : "https://www.hashicorp.com" ,
@@ -131,8 +170,8 @@ func TestAdminOPAVersions_CreateDelete(t *testing.T) {
131
170
assert .Equal (t , * opts .Beta , ov .Beta )
132
171
})
133
172
134
- t .Run ("with only required options" , func (t * testing.T ) {
135
- version : = createAdminOPAVersion ()
173
+ t .Run ("with only required options including tool version url and sha " , func (t * testing.T ) {
174
+ version = createAdminOPAVersion ()
136
175
opts := AdminOPAVersionCreateOptions {
137
176
Version : version ,
138
177
URL : "https://www.hashicorp.com" ,
@@ -156,6 +195,41 @@ func TestAdminOPAVersions_CreateDelete(t *testing.T) {
156
195
assert .Equal (t , false , ov .Beta )
157
196
})
158
197
198
+ t .Run ("with only required options including archs" , func (t * testing.T ) {
199
+ version = createAdminOPAVersion ()
200
+ opts := AdminOPAVersionCreateOptions {
201
+ Version : version ,
202
+ Archs : []* ToolVersionArchitecture {
203
+ {
204
+ URL : "https://www.hashicorp.com" ,
205
+ Sha : * String (genSha (t )),
206
+ OS : linux ,
207
+ Arch : amd64 ,
208
+ },
209
+ {
210
+ URL : "https://www.hashicorp.com" ,
211
+ Sha : * String (genSha (t )),
212
+ OS : linux ,
213
+ Arch : arm64 ,
214
+ }},
215
+ }
216
+ ov , err := client .Admin .OPAVersions .Create (ctx , opts )
217
+ require .NoError (t , err )
218
+
219
+ defer func () {
220
+ deleteErr := client .Admin .OPAVersions .Delete (ctx , ov .ID )
221
+ require .NoError (t , deleteErr )
222
+ }()
223
+
224
+ assert .Equal (t , opts .Version , ov .Version )
225
+ assert .ElementsMatch (t , opts .Archs , ov .Archs )
226
+ assert .Equal (t , false , ov .Official )
227
+ assert .Equal (t , false , ov .Deprecated )
228
+ assert .Nil (t , ov .DeprecatedReason )
229
+ assert .Equal (t , true , ov .Enabled )
230
+ assert .Equal (t , false , ov .Beta )
231
+ })
232
+
159
233
t .Run ("with empty options" , func (t * testing.T ) {
160
234
_ , err := client .Admin .OPAVersions .Create (ctx , AdminOPAVersionCreateOptions {})
161
235
require .Equal (t , err , ErrRequiredOPAVerCreateOps )
@@ -170,6 +244,7 @@ func TestAdminOPAVersions_ReadUpdate(t *testing.T) {
170
244
171
245
t .Run ("reads and updates" , func (t * testing.T ) {
172
246
version := createAdminOPAVersion ()
247
+ sha := String (genSha (t ))
173
248
opts := AdminOPAVersionCreateOptions {
174
249
Version : version ,
175
250
URL : "https://www.hashicorp.com" ,
@@ -179,6 +254,12 @@ func TestAdminOPAVersions_ReadUpdate(t *testing.T) {
179
254
DeprecatedReason : String ("Test Reason" ),
180
255
Enabled : Bool (false ),
181
256
Beta : Bool (false ),
257
+ Archs : []* ToolVersionArchitecture {{
258
+ URL : "https://www.hashicorp.com" ,
259
+ Sha : * sha ,
260
+ OS : linux ,
261
+ Arch : amd64 ,
262
+ }},
182
263
}
183
264
ov , err := client .Admin .OPAVersions .Create (ctx , opts )
184
265
require .NoError (t , err )
@@ -193,8 +274,9 @@ func TestAdminOPAVersions_ReadUpdate(t *testing.T) {
193
274
require .NoError (t , err )
194
275
195
276
assert .Equal (t , opts .Version , ov .Version )
196
- assert .Equal (t , opts .URL , ov .URL )
197
- assert .Equal (t , opts .SHA , ov .SHA )
277
+ assert .Equal (t , opts .Archs [0 ].URL , ov .URL )
278
+ assert .Equal (t , opts .Archs [0 ].Sha , ov .SHA )
279
+ assert .ElementsMatch (t , opts .Archs , ov .Archs )
198
280
assert .Equal (t , * opts .Official , ov .Official )
199
281
assert .Equal (t , * opts .Deprecated , ov .Deprecated )
200
282
assert .Equal (t , * opts .DeprecatedReason , * ov .DeprecatedReason )
@@ -215,10 +297,36 @@ func TestAdminOPAVersions_ReadUpdate(t *testing.T) {
215
297
assert .Equal (t , updateVersion , ov .Version )
216
298
assert .Equal (t , updateURL , ov .URL )
217
299
assert .Equal (t , opts .SHA , ov .SHA )
300
+ assert .Equal (t , updateURL , ov .Archs [0 ].URL )
301
+ assert .Equal (t , opts .SHA , ov .Archs [0 ].Sha )
218
302
assert .Equal (t , * opts .Official , ov .Official )
219
303
assert .Equal (t , * updateOpts .Deprecated , ov .Deprecated )
220
304
assert .Equal (t , * opts .Enabled , ov .Enabled )
221
305
assert .Equal (t , * opts .Beta , ov .Beta )
306
+
307
+ updateOpts = AdminOPAVersionUpdateOptions {
308
+ Archs : []* ToolVersionArchitecture {
309
+ {
310
+ URL : "https://www.hashicorp.com/update" ,
311
+ Sha : * sha ,
312
+ OS : linux ,
313
+ Arch : amd64 ,
314
+ },
315
+ {
316
+ URL : "https://www.hashicorp.com/update/arm64" ,
317
+ Sha : * sha ,
318
+ OS : linux ,
319
+ Arch : arm64 ,
320
+ },
321
+ },
322
+ }
323
+
324
+ ov , err = client .Admin .OPAVersions .Update (ctx , id , updateOpts )
325
+ require .NoError (t , err )
326
+
327
+ assert .Equal (t , "https://www.hashicorp.com/update" , ov .URL )
328
+ assert .Equal (t , opts .SHA , ov .SHA )
329
+ assert .ElementsMatch (t , updateOpts .Archs , ov .Archs )
222
330
})
223
331
224
332
t .Run ("with non-existent OPA version" , func (t * testing.T ) {
0 commit comments