@@ -1429,24 +1429,29 @@ func TestRPMCreateTemporaryRepositoryNoRPMFiles(t *testing.T) {
14291429}
14301430
14311431func TestRPMCreateTemporaryRepositoryCopyFails (t * testing.T ) {
1432- origShell := shell .Default
1433- defer func () { shell .Default = origShell }()
1434-
14351432 tmpDir := t .TempDir ()
1436- if err := os .WriteFile (filepath .Join (tmpDir , "pkg.rpm" ), []byte ("fake rpm" ), 0644 ); err != nil {
1433+ rpmPath := filepath .Join (tmpDir , "pkg.rpm" )
1434+ if err := os .WriteFile (rpmPath , []byte ("fake rpm" ), 0644 ); err != nil {
14371435 t .Fatalf ("failed to create rpm file: %v" , err )
14381436 }
14391437
1440- shell .Default = shell .NewMockExecutor ([]shell.MockCommand {
1441- {Pattern : "cp .*[.]rpm" , Output : "" , Error : fmt .Errorf ("permission denied" )},
1442- })
1438+ // CreateTemporaryRepository now copies files via copyFile(), so force a real
1439+ // read failure by removing read permissions from the source RPM.
1440+ if err := os .Chmod (rpmPath , 0000 ); err != nil {
1441+ t .Fatalf ("failed to chmod rpm file: %v" , err )
1442+ }
1443+ defer func () {
1444+ if chmodErr := os .Chmod (rpmPath , 0644 ); chmodErr != nil {
1445+ t .Fatalf ("failed to restore rpm file permissions: %v" , chmodErr )
1446+ }
1447+ }()
14431448
14441449 _ , _ , _ , err := CreateTemporaryRepository (tmpDir , "myrepo" )
14451450 if err == nil {
1446- t .Fatal ("expected error when cp fails" )
1451+ t .Fatal ("expected error when RPM copy fails" )
14471452 }
1448- if ! strings .Contains (err .Error (), "failed to copy RPM files " ) {
1449- t .Errorf ("expected 'failed to copy RPM files ' error, got: %v" , err )
1453+ if ! strings .Contains (err .Error (), "failed to copy RPM file " ) {
1454+ t .Errorf ("expected 'failed to copy RPM file ' error, got: %v" , err )
14501455 }
14511456}
14521457
0 commit comments