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