rhel85: add tests
This commit is contained in:
parent
4651b8ba22
commit
779103cb96
1 changed files with 204 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/rhel85"
|
||||
|
|
@ -23,6 +24,197 @@ var rhelFamilyDistros = []rhelFamilyDistro{
|
|||
},
|
||||
}
|
||||
|
||||
func TestFilenameFromType(t *testing.T) {
|
||||
type args struct {
|
||||
outputFormat string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
want1 string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "edge-container",
|
||||
args: args{"edge-container"},
|
||||
want: "container.tar",
|
||||
want1: "application/x-tar",
|
||||
},
|
||||
{
|
||||
name: "edge-installer",
|
||||
args: args{"edge-installer"},
|
||||
want: "installer.iso",
|
||||
want1: "application/x-iso9660-image",
|
||||
},
|
||||
{
|
||||
name: "invalid-output-type",
|
||||
args: args{"foobar"},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, dist := range rhelFamilyDistros {
|
||||
t.Run(dist.name, func(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dist := dist.distro
|
||||
arch, _ := dist.GetArch("x86_64")
|
||||
imgType, err := arch.GetImageType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Arch.GetImageType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !tt.wantErr {
|
||||
got := imgType.Filename()
|
||||
got1 := imgType.MIMEType()
|
||||
if got != tt.want {
|
||||
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got1 != tt.want1 {
|
||||
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageType_BuildPackages(t *testing.T) {
|
||||
x8664BuildPackages := []string{
|
||||
"dnf",
|
||||
"dosfstools",
|
||||
"e2fsprogs",
|
||||
"grub2-efi-x64",
|
||||
"grub2-pc",
|
||||
"policycoreutils",
|
||||
"shim-x64",
|
||||
"systemd",
|
||||
"tar",
|
||||
"qemu-img",
|
||||
"xz",
|
||||
}
|
||||
aarch64BuildPackages := []string{
|
||||
"dnf",
|
||||
"dosfstools",
|
||||
"e2fsprogs",
|
||||
"policycoreutils",
|
||||
"qemu-img",
|
||||
"systemd",
|
||||
"tar",
|
||||
"xz",
|
||||
}
|
||||
buildPackages := map[string][]string{
|
||||
"x86_64": x8664BuildPackages,
|
||||
"aarch64": aarch64BuildPackages,
|
||||
}
|
||||
for _, dist := range rhelFamilyDistros {
|
||||
t.Run(dist.name, func(t *testing.T) {
|
||||
d := dist.distro
|
||||
for _, archLabel := range d.ListArches() {
|
||||
archStruct, err := d.GetArch(archLabel)
|
||||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
for _, itLabel := range archStruct.ListImageTypes() {
|
||||
itStruct, err := archStruct.GetImageType(itLabel)
|
||||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{})["build"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs.Include)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageType_Name(t *testing.T) {
|
||||
imgMap := []struct {
|
||||
arch string
|
||||
imgNames []string
|
||||
}{
|
||||
{
|
||||
arch: "x86_64",
|
||||
imgNames: []string{
|
||||
"edge-commit",
|
||||
"edge-container",
|
||||
"edge-installer",
|
||||
},
|
||||
},
|
||||
{
|
||||
arch: "aarch64",
|
||||
imgNames: []string{
|
||||
"edge-commit",
|
||||
"edge-container",
|
||||
"edge-installer",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, dist := range rhelFamilyDistros {
|
||||
t.Run(dist.name, func(t *testing.T) {
|
||||
for _, mapping := range imgMap {
|
||||
if mapping.arch == "s390x" && dist.name == "centos" {
|
||||
continue
|
||||
}
|
||||
arch, err := dist.distro.GetArch(mapping.arch)
|
||||
if assert.NoError(t, err) {
|
||||
for _, imgName := range mapping.imgNames {
|
||||
if imgName == "edge-commit" && dist.name == "centos" {
|
||||
continue
|
||||
}
|
||||
imgType, err := arch.GetImageType(imgName)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equalf(t, imgName, imgType.Name(), "arch: %s", mapping.arch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Check that Manifest() function returns an error for unsupported
|
||||
// configurations.
|
||||
func TestDistro_ManifestError(t *testing.T) {
|
||||
// Currently, the only unsupported configuration is OSTree commit types
|
||||
// with Kernel boot options
|
||||
r8distro := rhel85.New()
|
||||
bp := blueprint.Blueprint{
|
||||
Customizations: &blueprint.Customizations{
|
||||
Kernel: &blueprint.KernelCustomization{
|
||||
Append: "debug",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, archName := range r8distro.ListArches() {
|
||||
arch, _ := r8distro.GetArch(archName)
|
||||
for _, imgTypeName := range arch.ListImageTypes() {
|
||||
if archName == "s390x" && imgTypeName == "tar" {
|
||||
// broken arch-imgType combination; see
|
||||
// https://github.com/osbuild/osbuild-composer/issues/1220
|
||||
continue
|
||||
}
|
||||
imgType, _ := arch.GetImageType(imgTypeName)
|
||||
imgOpts := distro.ImageOptions{
|
||||
Size: imgType.Size(0),
|
||||
}
|
||||
_, err := imgType.Manifest(bp.Customizations, imgOpts, nil, nil, 0)
|
||||
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
|
||||
assert.EqualError(t, err, "kernel boot parameter customizations are not supported for ostree types")
|
||||
} else if imgTypeName == "edge-installer" {
|
||||
assert.EqualError(t, err, "boot ISO image type \"edge-installer\" requires specifying a URL from which to retrieve the OSTree commit")
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArchitecture_ListImageTypes(t *testing.T) {
|
||||
imgMap := []struct {
|
||||
arch string
|
||||
|
|
@ -30,12 +222,20 @@ func TestArchitecture_ListImageTypes(t *testing.T) {
|
|||
rhelAdditionalImageTypes []string
|
||||
}{
|
||||
{
|
||||
arch: "x86_64",
|
||||
imgNames: []string{},
|
||||
arch: "x86_64",
|
||||
imgNames: []string{
|
||||
"edge-commit",
|
||||
"edge-container",
|
||||
"edge-installer",
|
||||
},
|
||||
},
|
||||
{
|
||||
arch: "aarch64",
|
||||
imgNames: []string{},
|
||||
arch: "aarch64",
|
||||
imgNames: []string{
|
||||
"edge-commit",
|
||||
"edge-container",
|
||||
"edge-installer",
|
||||
},
|
||||
},
|
||||
{
|
||||
arch: "ppc64le",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue