@@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"encoding/json"
22
22
"fmt"
23
+ "io"
23
24
"net/http"
24
25
"os"
25
26
"reflect"
@@ -276,6 +277,53 @@ func TestListOwnedProjects(t *testing.T) {
276
277
}
277
278
}
278
279
280
+ func TestEditProject (t * testing.T ) {
281
+ mux , client := setup (t )
282
+
283
+ var developerAccessLevel AccessControlValue = "developer"
284
+ opt := & EditProjectOptions {
285
+ CIRestrictPipelineCancellationRole : Ptr (developerAccessLevel ),
286
+ }
287
+
288
+ // Store whether we've set the restrict value in our edit properly
289
+ restrictValueSet := false
290
+
291
+ mux .HandleFunc ("/api/v4/projects/1" , func (w http.ResponseWriter , r * http.Request ) {
292
+ testMethod (t , r , http .MethodPut )
293
+
294
+ // Check that our request properly included ci_restrict_pipeline_cancellation_role
295
+ body , err := io .ReadAll (r .Body )
296
+ if err != nil {
297
+ t .Fatalf ("Unable to read body properly. Error: %v" , err )
298
+ }
299
+
300
+ // Set the value to check if our value is included
301
+ restrictValueSet = strings .Contains (string (body ), "ci_restrict_pipeline_cancellation_role" )
302
+
303
+ // Print the start of the mock example from https://docs.gitlab.com/ee/api/projects.html#edit-project
304
+ // including the attribute we edited
305
+ fmt .Fprint (w , `
306
+ {
307
+ "id": 1,
308
+ "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
309
+ "description_html": "<p data-sourcepos=\"1:1-1:56\" dir=\"auto\">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
310
+ "default_branch": "main",
311
+ "visibility": "private",
312
+ "ssh_url_to_repo": "[email protected] :diaspora/diaspora-project-site.git",
313
+ "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git",
314
+ "web_url": "http://example.com/diaspora/diaspora-project-site",
315
+ "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/main/README.md",
316
+ "ci_restrict_pipeline_cancellation_role": "developer"
317
+ }` )
318
+ })
319
+
320
+ project , resp , err := client .Projects .EditProject (1 , opt )
321
+ assert .NoError (t , err )
322
+ assert .Equal (t , http .StatusOK , resp .StatusCode )
323
+ assert .Equal (t , true , restrictValueSet )
324
+ assert .Equal (t , developerAccessLevel , project .CIRestrictPipelineCancellationRole )
325
+ }
326
+
279
327
func TestListStarredProjects (t * testing.T ) {
280
328
mux , client := setup (t )
281
329
@@ -323,6 +371,7 @@ func TestGetProjectByID(t *testing.T) {
323
371
"name_regex_keep": null,
324
372
"next_run_at": "2020-01-07T21:42:58.658Z"
325
373
},
374
+ "ci_restrict_pipeline_cancellation_role": "developer",
326
375
"packages_enabled": false,
327
376
"build_coverage_regex": "Total.*([0-9]{1,3})%"
328
377
}` )
@@ -336,8 +385,9 @@ func TestGetProjectByID(t *testing.T) {
336
385
Cadence : "7d" ,
337
386
NextRunAt : & wantTimestamp ,
338
387
},
339
- PackagesEnabled : false ,
340
- BuildCoverageRegex : `Total.*([0-9]{1,3})%` ,
388
+ PackagesEnabled : false ,
389
+ BuildCoverageRegex : `Total.*([0-9]{1,3})%` ,
390
+ CIRestrictPipelineCancellationRole : "developer" ,
341
391
}
342
392
343
393
project , _ , err := client .Projects .GetProject (1 , nil )
0 commit comments