@@ -43,9 +43,10 @@ func TestFilestore(t *testing.T) {
4343 a .EqualValues (42 , info .Size )
4444 a .EqualValues (0 , info .Offset )
4545 a .Equal (handler.MetaData {"hello" : "world" }, info .MetaData )
46- a .Equal (2 , len (info .Storage ))
46+ a .Equal (3 , len (info .Storage ))
4747 a .Equal ("filestore" , info .Storage ["Type" ])
4848 a .Equal (filepath .Join (tmp , info .ID ), info .Storage ["Path" ])
49+ a .Equal (filepath .Join (tmp , info .ID + ".info" ), info .Storage ["InfoPath" ])
4950
5051 // Write data to upload
5152 bytesWritten , err := upload .WriteChunk (ctx , 0 , strings .NewReader ("hello world" ))
@@ -104,9 +105,10 @@ func TestCreateDirectories(t *testing.T) {
104105 a .EqualValues (42 , info .Size )
105106 a .EqualValues (0 , info .Offset )
106107 a .Equal (handler.MetaData {"hello" : "world" }, info .MetaData )
107- a .Equal (2 , len (info .Storage ))
108+ a .Equal (3 , len (info .Storage ))
108109 a .Equal ("filestore" , info .Storage ["Type" ])
109110 a .Equal (filepath .Join (tmp , info .ID ), info .Storage ["Path" ])
111+ a .Equal (filepath .Join (tmp , info .ID + ".info" ), info .Storage ["InfoPath" ])
110112
111113 // Write data to upload
112114 bytesWritten , err := upload .WriteChunk (ctx , 0 , strings .NewReader ("hello world" ))
@@ -246,8 +248,9 @@ func TestDeclareLength(t *testing.T) {
246248 a .Equal (false , updatedInfo .SizeIsDeferred )
247249}
248250
249- // TestCustomPath tests whether the upload's destination can be customized.
250- func TestCustomPath (t * testing.T ) {
251+ // TestCustomRelativePath tests whether the upload's destination can be customized
252+ // relative to the storage directory.
253+ func TestCustomRelativePath (t * testing.T ) {
251254 a := assert .New (t )
252255
253256 tmp , err := os .MkdirTemp ("" , "tusd-filestore-" )
@@ -272,9 +275,10 @@ func TestCustomPath(t *testing.T) {
272275 a .NoError (err )
273276 a .EqualValues (42 , info .Size )
274277 a .EqualValues (0 , info .Offset )
275- a .Equal (2 , len (info .Storage ))
278+ a .Equal (3 , len (info .Storage ))
276279 a .Equal ("filestore" , info .Storage ["Type" ])
277280 a .Equal (filepath .Join (tmp , "./folder2/bin" ), info .Storage ["Path" ])
281+ a .Equal (filepath .Join (tmp , "./folder1/info.info" ), info .Storage ["InfoPath" ])
278282
279283 // Write data to upload
280284 bytesWritten , err := upload .WriteChunk (ctx , 0 , strings .NewReader ("hello world" ))
@@ -313,3 +317,44 @@ func TestCustomPath(t *testing.T) {
313317 a .Equal (nil , upload )
314318 a .Equal (handler .ErrNotFound , err )
315319}
320+
321+ // TestCustomAbsolutePath tests whether the upload's destination can be customized
322+ // using an absolute path to the storage directory.
323+ func TestCustomAbsolutePath (t * testing.T ) {
324+ a := assert .New (t )
325+
326+ tmp1 , err := os .MkdirTemp ("" , "tusd-filestore-" )
327+ a .NoError (err )
328+
329+ tmp2 , err := os .MkdirTemp ("" , "tusd-filestore-" )
330+ a .NoError (err )
331+
332+ store := FileStore {tmp1 }
333+ ctx := context .Background ()
334+
335+ // Create new upload, but the Path property points to a directory
336+ // outside of the directory given to FileStore
337+ binPath := filepath .Join (tmp2 , "dir/my-upload.bin" )
338+ upload , err := store .NewUpload (ctx , handler.FileInfo {
339+ ID : "my-upload" ,
340+ Size : 42 ,
341+ Storage : map [string ]string {
342+ "Path" : binPath ,
343+ },
344+ })
345+ a .NoError (err )
346+ a .NotEqual (nil , upload )
347+
348+ info , err := upload .GetInfo (ctx )
349+ a .NoError (err )
350+ a .EqualValues (42 , info .Size )
351+ a .EqualValues (0 , info .Offset )
352+ a .Equal (3 , len (info .Storage ))
353+ a .Equal ("filestore" , info .Storage ["Type" ])
354+ a .Equal (binPath , info .Storage ["Path" ])
355+ a .Equal (filepath .Join (tmp1 , "my-upload.info" ), info .Storage ["InfoPath" ])
356+
357+ statInfo , err := os .Stat (binPath )
358+ a .NoError (err )
359+ a .True (statInfo .Mode ().IsRegular ())
360+ }
0 commit comments