@@ -30,8 +30,7 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
30
30
req := NewRequestWithJSON (t , "POST" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" , getUploadArtifactRequest {
31
31
Type : "actions_storage" ,
32
32
Name : "artifact" ,
33
- })
34
- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
33
+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
35
34
resp := MakeRequest (t , req , http .StatusOK )
36
35
var uploadResp uploadArtifactResponse
37
36
DecodeJSON (t , resp , & uploadResp )
@@ -43,18 +42,18 @@ func TestActionsArtifactUploadSingleFile(t *testing.T) {
43
42
44
43
// upload artifact chunk
45
44
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))
51
50
MakeRequest (t , req , http .StatusOK )
52
51
53
52
t .Logf ("Create artifact confirm" )
54
53
55
54
// 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" )
58
57
MakeRequest (t , req , http .StatusOK )
59
58
}
60
59
@@ -64,20 +63,20 @@ func TestActionsArtifactUploadInvalidHash(t *testing.T) {
64
63
// artifact id 54321 not exist
65
64
url := "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts/8e5b948a454515dbabfc7eb718ddddddd/upload?itemPath=artifact/abc.txt"
66
65
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))
72
71
resp := MakeRequest (t , req , http .StatusBadRequest )
73
72
assert .Contains (t , resp .Body .String (), "Invalid artifact hash" )
74
73
}
75
74
76
75
func TestActionsArtifactConfirmUploadWithoutName (t * testing.T ) {
77
76
defer tests .PrepareTestEnv (t )()
78
77
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" )
81
80
resp := MakeRequest (t , req , http .StatusBadRequest )
82
81
assert .Contains (t , resp .Body .String (), "artifact name is empty" )
83
82
}
@@ -111,8 +110,8 @@ type (
111
110
func TestActionsArtifactDownload (t * testing.T ) {
112
111
defer tests .PrepareTestEnv (t )()
113
112
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" )
116
115
resp := MakeRequest (t , req , http .StatusOK )
117
116
var listResp listArtifactsResponse
118
117
DecodeJSON (t , resp , & listResp )
@@ -122,8 +121,8 @@ func TestActionsArtifactDownload(t *testing.T) {
122
121
123
122
idx := strings .Index (listResp .Value [0 ].FileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
124
123
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" )
127
126
resp = MakeRequest (t , req , http .StatusOK )
128
127
var downloadResp downloadArtifactResponse
129
128
DecodeJSON (t , resp , & downloadResp )
@@ -134,8 +133,8 @@ func TestActionsArtifactDownload(t *testing.T) {
134
133
135
134
idx = strings .Index (downloadResp .Value [0 ].ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
136
135
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" )
139
138
resp = MakeRequest (t , req , http .StatusOK )
140
139
body := strings .Repeat ("A" , 1024 )
141
140
assert .Equal (t , resp .Body .String (), body )
@@ -150,8 +149,7 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
150
149
req := NewRequestWithJSON (t , "POST" , "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts" , getUploadArtifactRequest {
151
150
Type : "actions_storage" ,
152
151
Name : testArtifactName ,
153
- })
154
- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
152
+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
155
153
resp := MakeRequest (t , req , http .StatusOK )
156
154
var uploadResp uploadArtifactResponse
157
155
DecodeJSON (t , resp , & uploadResp )
@@ -182,19 +180,19 @@ func TestActionsArtifactUploadMultipleFile(t *testing.T) {
182
180
url := uploadResp .FileContainerResourceURL [idx :] + "?itemPath=" + testArtifactName + "/" + f .Path
183
181
184
182
// 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))
190
188
MakeRequest (t , req , http .StatusOK )
191
189
}
192
190
193
191
t .Logf ("Create artifact confirm" )
194
192
195
193
// 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" )
198
196
MakeRequest (t , req , http .StatusOK )
199
197
}
200
198
@@ -203,8 +201,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
203
201
204
202
const testArtifactName = "multi-files"
205
203
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" )
208
206
resp := MakeRequest (t , req , http .StatusOK )
209
207
var listResp listArtifactsResponse
210
208
DecodeJSON (t , resp , & listResp )
@@ -221,8 +219,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
221
219
222
220
idx := strings .Index (fileContainerResourceURL , "/api/actions_pipeline/_apis/pipelines/" )
223
221
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" )
226
224
resp = MakeRequest (t , req , http .StatusOK )
227
225
var downloadResp downloadArtifactResponse
228
226
DecodeJSON (t , resp , & downloadResp )
@@ -246,8 +244,8 @@ func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
246
244
247
245
idx = strings .Index (value .ContentLocation , "/api/actions_pipeline/_apis/pipelines/" )
248
246
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" )
251
249
resp = MakeRequest (t , req , http .StatusOK )
252
250
body := strings .Repeat (bodyChar , 1024 )
253
251
assert .Equal (t , resp .Body .String (), body )
@@ -262,8 +260,7 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
262
260
Type : "actions_storage" ,
263
261
Name : "artifact-retention-days" ,
264
262
RetentionDays : 9 ,
265
- })
266
- req = addTokenAuthHeader (req , "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
263
+ }).AddTokenAuth ("8061e833a55f6fc0157c98b883e91fcfeeb1a71a" )
267
264
resp := MakeRequest (t , req , http .StatusOK )
268
265
var uploadResp uploadArtifactResponse
269
266
DecodeJSON (t , resp , & uploadResp )
@@ -276,17 +273,17 @@ func TestActionsArtifactUploadWithRetentionDays(t *testing.T) {
276
273
277
274
// upload artifact chunk
278
275
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))
284
281
MakeRequest (t , req , http .StatusOK )
285
282
286
283
t .Logf ("Create artifact confirm" )
287
284
288
285
// 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" )
291
288
MakeRequest (t , req , http .StatusOK )
292
289
}
0 commit comments