@@ -13,6 +13,7 @@ import (
1313 "strings"
1414 "testing"
1515
16+ "github.com/livekit/protocol/livekit"
1617 "github.com/stretchr/testify/require"
1718)
1819
@@ -45,11 +46,60 @@ func TestUploadTarball(t *testing.T) {
4546 f .Close ()
4647
4748 mockServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
49+ body , err := io .ReadAll (r .Body )
50+ require .NoError (t , err )
51+ require .NotZero (t , len (body ))
52+ require .Greater (t , fileSize , int64 (len (body )))
4853 w .WriteHeader (http .StatusOK )
4954 }))
5055 defer mockServer .Close ()
5156
52- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
57+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
58+ require .NoError (t , err )
59+ }
60+
61+ func TestUploadTarballPost (t * testing.T ) {
62+ tmpDir , err := os .MkdirTemp ("" , "tarball-test-*" )
63+ require .NoError (t , err )
64+ defer os .RemoveAll (tmpDir )
65+
66+ subDir := filepath .Join (tmpDir , "subdir" )
67+ err = os .MkdirAll (subDir , 0755 )
68+ require .NoError (t , err )
69+
70+ normalFiles := []string {
71+ filepath .Join (subDir , "normal1.txt" ),
72+ filepath .Join (subDir , "normal2.txt" ),
73+ filepath .Join (tmpDir , "root.txt" ),
74+ }
75+ for _ , path := range normalFiles {
76+ err = os .WriteFile (path , []byte ("normal content" ), 0644 )
77+ require .NoError (t , err )
78+ }
79+
80+ largeFile := filepath .Join (tmpDir , "large.bin" )
81+ f , err := os .Create (largeFile )
82+ require .NoError (t , err )
83+
84+ fileSize := int64 (1024 * 1024 * 1024 ) // 1GB
85+ err = f .Truncate (fileSize )
86+ require .NoError (t , err )
87+ f .Close ()
88+
89+ mockServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
90+ err := r .ParseMultipartForm (1024 * 1024 * 1024 )
91+ require .NoError (t , err )
92+ require .NotZero (t , len (r .MultipartForm .File ["file" ]))
93+ require .Equal (t , "upload.tar.gz" , r .MultipartForm .File ["file" ][0 ].Filename )
94+ require .Greater (t , fileSize , r .MultipartForm .File ["file" ][0 ].Size )
95+ w .WriteHeader (http .StatusCreated )
96+ }))
97+ defer mockServer .Close ()
98+
99+ err = UploadTarball (tmpDir , "" , & livekit.PresignedPostRequest {
100+ Url : mockServer .URL ,
101+ Values : map [string ]string {},
102+ }, []string {}, ProjectTypePythonPip )
53103 require .NoError (t , err )
54104}
55105
@@ -86,15 +136,15 @@ func TestUploadTarballFilePermissions(t *testing.T) {
86136 // https://learn.microsoft.com/en-us/windows/win32/secauthz/access-control-lists
87137 //
88138 if runtime .GOOS != "windows" {
89- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
139+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
90140 require .Error (t , err )
91141 require .Contains (t , err .Error (), "permission denied" )
92142 }
93143
94144 err = os .Remove (restrictedFile )
95145 require .NoError (t , err )
96146
97- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
147+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
98148 require .NoError (t , err )
99149}
100150
@@ -189,7 +239,7 @@ func TestUploadTarballDotfiles(t *testing.T) {
189239 }))
190240 defer mockServer .Close ()
191241
192- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
242+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
193243 require .NoError (t , err )
194244
195245 contents := readTarContents (t , tarBuffer .Bytes ())
@@ -273,7 +323,7 @@ func TestUploadTarballDeepDirectories(t *testing.T) {
273323 }))
274324 defer mockServer .Close ()
275325
276- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
326+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
277327 require .NoError (t , err )
278328
279329 contents := readTarContents (t , tarBuffer .Bytes ())
@@ -370,7 +420,7 @@ venv/
370420 }))
371421 defer mockServer .Close ()
372422
373- err = UploadTarball (tmpDir , mockServer .URL , []string {}, ProjectTypePythonPip )
423+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {}, ProjectTypePythonPip )
374424 require .NoError (t , err )
375425
376426 contents := readTarContents (t , tarBuffer .Bytes ())
@@ -474,7 +524,7 @@ func TestUploadTarballWithPipPythonProject(t *testing.T) {
474524 }))
475525 defer mockServer .Close ()
476526
477- err = UploadTarball (tmpDir , mockServer .URL , []string {"**/livekit.toml" }, ProjectTypePythonPip )
527+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {"**/livekit.toml" }, ProjectTypePythonPip )
478528 require .NoError (t , err )
479529
480530 contents := readTarContents (t , tarBuffer .Bytes ())
@@ -567,7 +617,7 @@ func TestUploadTarballWithUvPythonProject(t *testing.T) {
567617 }))
568618 defer mockServer .Close ()
569619
570- err = UploadTarball (tmpDir , mockServer .URL , []string {"**/livekit.toml" }, ProjectTypePythonUV )
620+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {"**/livekit.toml" }, ProjectTypePythonUV )
571621 require .NoError (t , err )
572622
573623 contents := readTarContents (t , tarBuffer .Bytes ())
@@ -667,7 +717,7 @@ func TestUploadTarballWithNodeProject(t *testing.T) {
667717 }))
668718 defer mockServer .Close ()
669719
670- err = UploadTarball (tmpDir , mockServer .URL , []string {"**/livekit.toml" }, ProjectTypeNode )
720+ err = UploadTarball (tmpDir , mockServer .URL , nil , []string {"**/livekit.toml" }, ProjectTypeNode )
671721 require .NoError (t , err )
672722
673723 contents := readTarContents (t , tarBuffer .Bytes ())
0 commit comments