@@ -181,7 +181,7 @@ func TestCopyMerge(t *testing.T) {
181181 WithResource (pkgbuilder .DeploymentResource ),
182182 ),
183183 },
184- "update existing file in origin, local, and updated " : {
184+ "file removal if file exists in origin but not in update " : {
185185 origin : pkgbuilder .NewRootPkg ().
186186 WithKptfile (
187187 pkgbuilder .NewKptfile ().
@@ -207,8 +207,7 @@ func TestCopyMerge(t *testing.T) {
207207 pkgbuilder .NewKptfile ().
208208 WithUpstream (kptRepo , "/origin" , "master" , copyMergeLiteral ).
209209 WithUpstreamLock (kptRepo , "/origin" , "master" , "abc123" ),
210- ).
211- WithResource (pkgbuilder .DeploymentResource ),
210+ ),
212211 },
213212 }
214213
@@ -415,3 +414,33 @@ func TestCopyMergeDifferentMetadata(t *testing.T) {
415414 })
416415 }
417416}
417+
418+ func TestCopyMergeErrorRemovingFile (t * testing.T ) {
419+ src := t .TempDir ()
420+ dst := t .TempDir ()
421+ org := t .TempDir ()
422+
423+ // Create a file in org and dst, but not in src (so RemoveStaleItems will try to remove it)
424+ fileName := "file.txt"
425+ filePathDst := filepath .Join (dst , fileName )
426+ filePathOrg := filepath .Join (org , fileName )
427+
428+ assert .NoError (t , os .WriteFile (filePathDst , []byte ("content" ), 0644 ))
429+ assert .NoError (t , os .WriteFile (filePathOrg , []byte ("content" ), 0644 ))
430+
431+ assert .NoError (t , os .Remove (filePathDst ))
432+ assert .NoError (t , os .Mkdir (filePathDst , 0755 ))
433+ assert .NoError (t , os .WriteFile (filepath .Join (filePathDst , "dummy" ), []byte ("x" ), 0644 ))
434+
435+ updater := & CopyMergeUpdater {}
436+ options := Options {
437+ OriginPath : org ,
438+ UpdatedPath : src ,
439+ LocalPath : dst ,
440+ IsRoot : true ,
441+ }
442+
443+ err := updater .Update (options )
444+ assert .Error (t , err )
445+ assert .Contains (t , err .Error (), "directory not empty" )
446+ }
0 commit comments