Skip to content

Commit

Permalink
added handling and tests for when user doesn't add rpms
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Nov 1, 2023
1 parent 2f489d9 commit 53c7d68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/build/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func (b *Builder) getRPMFileNames(rpmSourceDir string) ([]string, error) {

func (b *Builder) copyRPMs() error {
rpmSourceDir := filepath.Join(b.buildConfig.ImageConfigDir, "rpms")
// Only proceed with copying the RPMs if the directory exists
_, err := os.Stat(rpmSourceDir)
if err != nil {
if os.IsNotExist(err) {
return nil
} else {

Check warning on line 37 in pkg/build/rpm.go

View workflow job for this annotation

GitHub Actions / lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return fmt.Errorf("checking for rpm directory at %s: %w", rpmSourceDir, err)
}
}
rpmDestDir := b.combustionDir

rpmFileNames, err := b.getRPMFileNames(rpmSourceDir)
Expand Down
17 changes: 17 additions & 0 deletions pkg/build/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,20 @@ func TestGetRPMFileNamesNoRPMs(t *testing.T) {

assert.Empty(t, rpmFileNames)
}

func TestCopyRPMsNoRPMDir(t *testing.T) {
// Setup
bc := config.BuildConfig{
ImageConfigDir: "../config/ThisDirDoesNotExist",
}
builder := New(nil, &bc)
err := builder.prepareBuildDir()
require.NoError(t, err)
defer os.Remove(builder.eibBuildDir)

// Test
err = builder.copyRPMs()

// Verify
require.NoError(t, err)
}

0 comments on commit 53c7d68

Please sign in to comment.