@@ -245,3 +245,71 @@ func TestDeclareLength(t *testing.T) {
245
245
a .EqualValues (100 , updatedInfo .Size )
246
246
a .Equal (false , updatedInfo .SizeIsDeferred )
247
247
}
248
+
249
+ // TestCustomPath tests whether the upload's destination can be customized.
250
+ func TestCustomPath (t * testing.T ) {
251
+ a := assert .New (t )
252
+
253
+ tmp , err := os .MkdirTemp ("" , "tusd-filestore-" )
254
+ a .NoError (err )
255
+
256
+ store := FileStore {tmp }
257
+ ctx := context .Background ()
258
+
259
+ // Create new upload
260
+ upload , err := store .NewUpload (ctx , handler.FileInfo {
261
+ ID : "folder1/info" ,
262
+ Size : 42 ,
263
+ Storage : map [string ]string {
264
+ "Path" : "./folder2/bin" ,
265
+ },
266
+ })
267
+ a .NoError (err )
268
+ a .NotEqual (nil , upload )
269
+
270
+ // Check info without writing
271
+ info , err := upload .GetInfo (ctx )
272
+ a .NoError (err )
273
+ a .EqualValues (42 , info .Size )
274
+ a .EqualValues (0 , info .Offset )
275
+ a .Equal (2 , len (info .Storage ))
276
+ a .Equal ("filestore" , info .Storage ["Type" ])
277
+ a .Equal (filepath .Join (tmp , "./folder2/bin" ), info .Storage ["Path" ])
278
+
279
+ // Write data to upload
280
+ bytesWritten , err := upload .WriteChunk (ctx , 0 , strings .NewReader ("hello world" ))
281
+ a .NoError (err )
282
+ a .EqualValues (len ("hello world" ), bytesWritten )
283
+
284
+ // Check new offset
285
+ info , err = upload .GetInfo (ctx )
286
+ a .NoError (err )
287
+ a .EqualValues (42 , info .Size )
288
+ a .EqualValues (11 , info .Offset )
289
+
290
+ // Read content
291
+ reader , err := upload .GetReader (ctx )
292
+ a .NoError (err )
293
+
294
+ content , err := io .ReadAll (reader )
295
+ a .NoError (err )
296
+ a .Equal ("hello world" , string (content ))
297
+ reader .(io.Closer ).Close ()
298
+
299
+ // Check that the output file and info file exist on disk
300
+ statInfo , err := os .Stat (filepath .Join (tmp , "folder2/bin" ))
301
+ a .NoError (err )
302
+ a .True (statInfo .Mode ().IsRegular ())
303
+ a .EqualValues (11 , statInfo .Size ())
304
+ statInfo , err = os .Stat (filepath .Join (tmp , "folder1/info.info" ))
305
+ a .NoError (err )
306
+ a .True (statInfo .Mode ().IsRegular ())
307
+
308
+ // Terminate upload
309
+ a .NoError (store .AsTerminatableUpload (upload ).Terminate (ctx ))
310
+
311
+ // Test if upload is deleted
312
+ upload , err = store .GetUpload (ctx , info .ID )
313
+ a .Equal (nil , upload )
314
+ a .Equal (handler .ErrNotFound , err )
315
+ }
0 commit comments