-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added handling for adding rpms to an image as well as the relevant tests
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func (b *Builder) getRPMFileNames() error { | ||
b.rpmSourceDir = filepath.Join(b.buildConfig.ImageConfigDir, "rpms") | ||
|
||
rpms, err := os.ReadDir(b.rpmSourceDir) | ||
if err != nil { | ||
return fmt.Errorf("reading rpm source dir: %w", err) | ||
} | ||
|
||
for _, rpmFile := range rpms { | ||
b.rpmFileNames = append(b.rpmFileNames, rpmFile.Name()) | ||
} | ||
return nil | ||
} | ||
|
||
func (b *Builder) copyRPMs() error { | ||
err := b.getRPMFileNames() | ||
if err != nil { | ||
return fmt.Errorf("getting rpm file names: %w", err) | ||
} | ||
|
||
for _, rpm := range b.rpmFileNames { | ||
sourcePath := filepath.Join(b.rpmSourceDir, rpm) | ||
destPath := filepath.Join(b.rpmBuildDir, rpm) | ||
|
||
sourceFile, err := os.Open(sourcePath) | ||
if err != nil { | ||
return fmt.Errorf("opening rpm source path: %w", err) | ||
} | ||
defer sourceFile.Close() | ||
|
||
destFile, err := os.Create(destPath) | ||
if err != nil { | ||
return fmt.Errorf("opening rpm dest path: %w", err) | ||
} | ||
defer destFile.Close() | ||
|
||
_, err = io.Copy(destFile, sourceFile) | ||
if err != nil { | ||
return fmt.Errorf("copying rpm: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package build | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/suse-edge/edge-image-builder/pkg/config" | ||
) | ||
|
||
func TestGetRPMFileNames(t *testing.T) { | ||
// Setup | ||
bc := config.BuildConfig{ | ||
ImageConfigDir: "../config/testdata", | ||
} | ||
builder := New(nil, &bc) | ||
err := builder.prepareBuildDir() | ||
require.NoError(t, err) | ||
defer os.Remove(builder.eibBuildDir) | ||
|
||
// Test | ||
err = builder.getRPMFileNames() | ||
|
||
// Verify | ||
require.NoError(t, err) | ||
|
||
assert.Contains(t, builder.rpmFileNames, "rpm1.rpm") | ||
assert.Contains(t, builder.rpmFileNames, "rpm2.rpm") | ||
} | ||
|
||
func TestCopyRPMs(t *testing.T) { | ||
// Setup | ||
bc := config.BuildConfig{ | ||
ImageConfigDir: "../config/testdata", | ||
} | ||
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) | ||
|
||
_, err = os.Stat(filepath.Join(builder.rpmBuildDir, "rpm1.rpm")) | ||
require.NoError(t, err) | ||
|
||
_, err = os.Stat(filepath.Join(builder.rpmBuildDir, "rpm2.rpm")) | ||
require.NoError(t, err) | ||
} |
Empty file.
Empty file.