@@ -262,6 +262,71 @@ func TestUploadFiles_Cancelation(t *testing.T) {
262262 require .ErrorIs (t , err , gocontext .Canceled )
263263}
264264
265+ func TestUploadFiles_SkipEqualFiles (t * testing.T ) {
266+ ctx := gocontext .Background ()
267+
268+ serverRequests := 0
269+
270+ server := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {
271+ serverRequests ++
272+
273+ rw .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
274+ rw .Write ([]byte (`{}` ))
275+ }))
276+ defer server .Close ()
277+
278+ hu , _ := url .Parse (server .URL )
279+ tr := apiClient .NewWithClient (hu .Host , "/api/v1" , []string {"http" }, http .DefaultClient )
280+ client := NewRetryable (tr , strfmt .Default , 1 )
281+ client .uploadLimit = 1
282+ ctx = context .WithAuthInfo (ctx , apiClient .BearerToken ("token" ))
283+
284+ // Create some files to deploy
285+ dir , err := ioutil .TempDir ("" , "deploy" )
286+ require .NoError (t , err )
287+ defer os .RemoveAll (dir )
288+
289+ fileBody := []byte ("Hello" )
290+
291+ require .NoError (t , ioutil .WriteFile (filepath .Join (dir , "a.html" ), fileBody , 0644 ))
292+ require .NoError (t , ioutil .WriteFile (filepath .Join (dir , "b.html" ), fileBody , 0644 ))
293+
294+ files , err := walk (dir , nil , false , false )
295+ require .NoError (t , err )
296+
297+ // Create some fake function bundles to deploy
298+ functionsDir , err := ioutil .TempDir ("" , "deploy-functions" )
299+ require .NoError (t , err )
300+ defer os .RemoveAll (functionsDir )
301+
302+ // Get the JS function bundle
303+ cwd , _ := os .Getwd ()
304+ basePath := path .Join (filepath .Dir (cwd ), "internal" , "data" )
305+ jsFunctionPath := strings .Replace (filepath .Join (basePath , "hello-js-function-test.zip" ), "\\ " , "/" , - 1 )
306+ bundleBody , err := ioutil .ReadFile (jsFunctionPath )
307+ require .NoError (t , err )
308+
309+ require .NoError (t , ioutil .WriteFile (filepath .Join (functionsDir , "a.zip" ), bundleBody , 0644 ))
310+ require .NoError (t , ioutil .WriteFile (filepath .Join (functionsDir , "b.zip" ), bundleBody , 0644 ))
311+
312+ functions , _ , _ , err := bundle (ctx , functionsDir , mockObserver {})
313+ require .NoError (t , err )
314+
315+ d := & models.Deploy {}
316+ // uploadFiles relies on the fact that the list of sums is an array of unique values, as both
317+ // the files and bundles have the same SHA we only need one of them for the Required array
318+ d .Required = []string {files .Sums ["a.html" ]}
319+ d .RequiredFunctions = []string {functions .Sums ["a" ]}
320+
321+ err = client .uploadFiles (ctx , d , files , nil , fileUpload , time .Minute )
322+ require .NoError (t , err )
323+ assert .Equal (t , 1 , serverRequests )
324+
325+ err = client .uploadFiles (ctx , d , functions , nil , functionUpload , time .Minute )
326+ require .NoError (t , err )
327+ assert .Equal (t , 2 , serverRequests )
328+ }
329+
265330func TestUploadFunctions_RetryCountHeader (t * testing.T ) {
266331 attempts := 0
267332 ctx , cancel := gocontext .WithCancel (gocontext .Background ())
0 commit comments