@@ -30,8 +30,7 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
3030 req := NewRequestWithJSON (t , "POST" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" , getUploadArtifactRequest {
3131 Type : "actions_storage" ,
3232 Name : "artifact" ,
33- })
34- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
33+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
3534 resp := MakeRequest (t , req , http .StatusOK )
3635 var uploadResp uploadArtifactResponse
3736 DecodeJSON (t , resp , & uploadResp )
@@ -43,18 +42,18 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
4342
4443 // upload artifact chunk
4544 body := strings .Repeat ("A" , 1024 )
46- req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (body ))
47- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
48- req . Header . Add ("Content-Range" , "bytes 0-1023/1024" )
49- req . Header . Add ("x-tfs-filelength" , "1024" )
50- req . Header . Add ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
45+ req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (body )).
46+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" ).
47+ SetHeader ("Content-Range" , "bytes 0-1023/1024" ).
48+ SetHeader ("x-tfs-filelength" , "1024" ).
49+ SetHeader ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
5150 MakeRequest (t , req , http .StatusOK )
5251
5352 t .Logf ("Create artifact confirm" )
5453
5554 // confirm artifact upload
56- req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact" )
57- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
55+ req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact" ).
56+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
5857 MakeRequest (t , req , http .StatusOK )
5958}
6059
@@ -64,20 +63,20 @@ func TestActionsArtifactUploadInvalidHash(t *testing.T) {
6463 // artifact id 54321 not exist
6564 url := "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts/8e5b948a454515dbabfc7eb718ddddddd/upload?itemPath=artifact/abc.txt"
6665 body := strings .Repeat ("A" , 1024 )
67- req := NewRequestWithBody (t , "PUT" , url , strings .NewReader (body ))
68- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
69- req . Header . Add ("Content-Range" , "bytes 0-1023/1024" )
70- req . Header . Add ("x-tfs-filelength" , "1024" )
71- req . Header . Add ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
66+ req := NewRequestWithBody (t , "PUT" , url , strings .NewReader (body )).
67+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" ).
68+ SetHeader ("Content-Range" , "bytes 0-1023/1024" ).
69+ SetHeader ("x-tfs-filelength" , "1024" ).
70+ SetHeader ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
7271 resp := MakeRequest (t , req , http .StatusBadRequest )
7372 assert .Contains (t , resp .Body .String (), "Invalid artifact hash" )
7473}
7574
7675func TestActionsArtifactConfirmUploadWithoutName (t * testing.T ) {
7776 defer tests .PrepareTestEnv (t )()
7877
79- req := NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" )
80- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
78+ req := NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" ).
79+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
8180 resp := MakeRequest (t , req , http .StatusBadRequest )
8281 assert .Contains (t , resp .Body .String (), "artifact name is empty" )
8382}
@@ -111,8 +110,8 @@ type (
111110func TestActionsArtifactDownload (t * testing.T ) {
112111 defer tests .PrepareTestEnv (t )()
113112
114- req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" )
115- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
113+ req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" ).
114+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
116115 resp := MakeRequest (t , req , http .StatusOK )
117116 var listResp listArtifactsResponse
118117 DecodeJSON (t , resp , & listResp )
@@ -122,8 +121,8 @@ func TestActionsArtifactDownload(t *testing.T) {
122121
123122 idx := strings .Index (listResp .Value [0 ].FileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
124123 url := listResp .Value [0 ].FileContainerResourceURL [idx + 1 :] + "?itemPath=artifact"
125- req = NewRequest (t , "GET" , url )
126- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
124+ req = NewRequest (t , "GET" , url ).
125+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
127126 resp = MakeRequest (t , req , http .StatusOK )
128127 var downloadResp downloadArtifactResponse
129128 DecodeJSON (t , resp , & downloadResp )
@@ -134,8 +133,8 @@ func TestActionsArtifactDownload(t *testing.T) {
134133
135134 idx = strings .Index (downloadResp .Value [0 ].ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
136135 url = downloadResp .Value [0 ].ContentLocation [idx :]
137- req = NewRequest (t , "GET" , url )
138- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
136+ req = NewRequest (t , "GET" , url ).
137+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
139138 resp = MakeRequest (t , req , http .StatusOK )
140139 body := strings .Repeat ("A" , 1024 )
141140 assert .Equal (t , resp .Body .String (), body )
@@ -150,8 +149,7 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
150149 req := NewRequestWithJSON (t , "POST" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" , getUploadArtifactRequest {
151150 Type : "actions_storage" ,
152151 Name : testArtifactName ,
153- })
154- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
152+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
155153 resp := MakeRequest (t , req , http .StatusOK )
156154 var uploadResp uploadArtifactResponse
157155 DecodeJSON (t , resp , & uploadResp )
@@ -182,19 +180,19 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
182180 url := uploadResp .FileContainerResourceURL [idx :] + "?itemPath=" + testArtifactName + "/" + f .Path
183181
184182 // upload artifact chunk
185- req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (f .Content ))
186- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
187- req . Header . Add ("Content-Range" , "bytes 0-1023/1024" )
188- req . Header . Add ("x-tfs-filelength" , "1024" )
189- req . Header . Add ("x-actions-results-md5" , f .MD5 ) // base64(md5(body))
183+ req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (f .Content )).
184+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" ).
185+ SetHeader ("Content-Range" , "bytes 0-1023/1024" ).
186+ SetHeader ("x-tfs-filelength" , "1024" ).
187+ SetHeader ("x-actions-results-md5" , f .MD5 ) // base64(md5(body))
190188 MakeRequest (t , req , http .StatusOK )
191189 }
192190
193191 t .Logf ("Create artifact confirm" )
194192
195193 // confirm artifact upload
196- req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=" + testArtifactName )
197- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
194+ req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=" + testArtifactName ).
195+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
198196 MakeRequest (t , req , http .StatusOK )
199197}
200198
@@ -203,8 +201,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
203201
204202 const testArtifactName = "multi-files"
205203
206- req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" )
207- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
204+ req := NewRequest (t , "GET" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" ).
205+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
208206 resp := MakeRequest (t , req , http .StatusOK )
209207 var listResp listArtifactsResponse
210208 DecodeJSON (t , resp , & listResp )
@@ -221,8 +219,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
221219
222220 idx := strings .Index (fileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
223221 url := fileContainerResourceURL [idx + 1 :] + "?itemPath=" + testArtifactName
224- req = NewRequest (t , "GET" , url )
225- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
222+ req = NewRequest (t , "GET" , url ).
223+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
226224 resp = MakeRequest (t , req , http .StatusOK )
227225 var downloadResp downloadArtifactResponse
228226 DecodeJSON (t , resp , & downloadResp )
@@ -246,8 +244,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
246244
247245 idx = strings .Index (value .ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
248246 url = value .ContentLocation [idx :]
249- req = NewRequest (t , "GET" , url )
250- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
247+ req = NewRequest (t , "GET" , url ).
248+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
251249 resp = MakeRequest (t , req , http .StatusOK )
252250 body := strings .Repeat (bodyChar , 1024 )
253251 assert .Equal (t , resp .Body .String (), body )
@@ -262,8 +260,7 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
262260 Type : "actions_storage" ,
263261 Name : "artifact-retention-days" ,
264262 RetentionDays : 9 ,
265- })
266- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
263+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
267264 resp := MakeRequest (t , req , http .StatusOK )
268265 var uploadResp uploadArtifactResponse
269266 DecodeJSON (t , resp , & uploadResp )
@@ -276,17 +273,17 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
276273
277274 // upload artifact chunk
278275 body := strings .Repeat ("A" , 1024 )
279- req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (body ))
280- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
281- req . Header . Add ("Content-Range" , "bytes 0-1023/1024" )
282- req . Header . Add ("x-tfs-filelength" , "1024" )
283- req . Header . Add ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
276+ req = NewRequestWithBody (t , "PUT" , url , strings .NewReader (body )).
277+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" ).
278+ SetHeader ("Content-Range" , "bytes 0-1023/1024" ).
279+ SetHeader ("x-tfs-filelength" , "1024" ).
280+ SetHeader ("x-actions-results-md5" , "1HsSe8LeLWh93ILaw1TEFQ==" ) // base64(md5(body))
284281 MakeRequest (t , req , http .StatusOK )
285282
286283 t .Logf ("Create artifact confirm" )
287284
288285 // confirm artifact upload
289- req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact-retention-days" )
290- req = addTokenAuthHeader ( req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
286+ req = NewRequest (t , "PATCH" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact-retention-days" ).
287+ AddTokenAuth ( " 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
291288 MakeRequest (t , req , http .StatusOK )
292289}
0 commit comments