@@ -287,3 +287,92 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
287
287
AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
288
288
MakeRequest (t , req , http .StatusOK )
289
289
}
290
+
291
+ func TestActionsArtifactOverwrite (t * testing.T ) {
292
+ defer tests .PrepareTestEnv (t )()
293
+
294
+ {
295
+ // download old artifact uploaded by tests above, it should 1024 A
296
+ req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" ).
297
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
298
+ resp := MakeRequest (t , req , http .StatusOK )
299
+ var listResp listArtifactsResponse
300
+ DecodeJSON (t , resp , & listResp )
301
+
302
+ idx := strings .Index (listResp .Value [0 ].FileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
303
+ url := listResp .Value [0 ].FileContainerResourceURL [idx + 1 :] + "?itemPath=artifact"
304
+ req = NewRequest (t , "GET" , url ).
305
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
306
+ resp = MakeRequest (t , req , http .StatusOK )
307
+ var downloadResp downloadArtifactResponse
308
+ DecodeJSON (t , resp , & downloadResp )
309
+
310
+ idx = strings .Index (downloadResp .Value [0 ].ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
311
+ url = downloadResp .Value [0 ].ContentLocation [idx :]
312
+ req = NewRequest (t , "GET" , url ).
313
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
314
+ resp = MakeRequest (t , req , http .StatusOK )
315
+ body := strings .Repeat ("A" , 1024 )
316
+ assert .Equal (t , resp .Body .String (), body )
317
+ }
318
+
319
+ {
320
+ // upload same artifact, it uses 4096 B
321
+ req := NewRequestWithJSON (t , "POST" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" , getUploadArtifactRequest {
322
+ Type : "actions_storage" ,
323
+ Name : "artifact" ,
324
+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
325
+ resp := MakeRequest (t , req , http .StatusOK )
326
+ var uploadResp uploadArtifactResponse
327
+ DecodeJSON (t , resp , & uploadResp )
328
+
329
+ idx := strings .Index (uploadResp .FileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
330
+ url := uploadResp .FileContainerResourceURL [idx :] + "?itemPath=artifact/abc.txt"
331
+ body := strings .Repeat ("B" , 4096 )
332
+ req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (body )).
333
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" ).
334
+ SetHeader ("Content-Range" , "bytes 0-4095/4096" ).
335
+ SetHeader ("x-tfs-filelength" , "4096" ).
336
+ SetHeader ("x-actions-results-md5" , "wUypcJFeZCK5T6r4lfqzqg==" ) // base64(md5(body))
337
+ MakeRequest (t , req , http .StatusOK )
338
+
339
+ // confirm artifact upload
340
+ req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact" ).
341
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
342
+ MakeRequest (t , req , http .StatusOK )
343
+ }
344
+
345
+ {
346
+ // download artifact again, it should 4096 B
347
+ req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" ).
348
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
349
+ resp := MakeRequest (t , req , http .StatusOK )
350
+ var listResp listArtifactsResponse
351
+ DecodeJSON (t , resp , & listResp )
352
+
353
+ var uploadedItem listArtifactsResponseItem
354
+ for _ , item := range listResp .Value {
355
+ if item .Name == "artifact" {
356
+ uploadedItem = item
357
+ break
358
+ }
359
+ }
360
+ assert .Equal (t , uploadedItem .Name , "artifact" )
361
+
362
+ idx := strings .Index (uploadedItem .FileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
363
+ url := uploadedItem .FileContainerResourceURL [idx + 1 :] + "?itemPath=artifact"
364
+ req = NewRequest (t , "GET" , url ).
365
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
366
+ resp = MakeRequest (t , req , http .StatusOK )
367
+ var downloadResp downloadArtifactResponse
368
+ DecodeJSON (t , resp , & downloadResp )
369
+
370
+ idx = strings .Index (downloadResp .Value [0 ].ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
371
+ url = downloadResp .Value [0 ].ContentLocation [idx :]
372
+ req = NewRequest (t , "GET" , url ).
373
+ AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
374
+ resp = MakeRequest (t , req , http .StatusOK )
375
+ body := strings .Repeat ("B" , 4096 )
376
+ assert .Equal (t , resp .Body .String (), body )
377
+ }
378
+ }
0 commit comments