From db4b6e71ed6b080c47f52102b49e7722ced01344 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Fri, 27 Mar 2020 20:44:23 +0100 Subject: [PATCH] distro_test: add test that covers BuildPackages The main reason here is not to make sure we have the right set of build packages, but rather to make sure the pointer hierarchy (distro->arch-> image type) works as expected. --- internal/distro/fedora30/distro_test.go | 45 +++++++++++++++++++++++++ internal/distro/fedora31/distro_test.go | 45 +++++++++++++++++++++++++ internal/distro/fedora32/distro_test.go | 45 +++++++++++++++++++++++++ 3 files changed, 135 insertions(+) diff --git a/internal/distro/fedora30/distro_test.go b/internal/distro/fedora30/distro_test.go index 26b3c1141..b1d3bb9d0 100644 --- a/internal/distro/fedora30/distro_test.go +++ b/internal/distro/fedora30/distro_test.go @@ -2,6 +2,7 @@ package fedora30_test import ( "github.com/osbuild/osbuild-composer/internal/distro/fedora30" + "reflect" "testing" ) @@ -92,3 +93,47 @@ func TestFilenameFromType(t *testing.T) { }) } } + +func TestImageType_BuildPackages(t *testing.T) { + x8664BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "grub2-pc", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + aarch64BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + buildPackages := map[string][]string{ + "x86_64": x8664BuildPackages, + "aarch64": aarch64BuildPackages, + } + d := fedora30.New() + for _, archLabel := range d.ListArchs() { + archStruct, err := d.GetArch(archLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + for _, itLabel := range archStruct.ListImageTypes() { + itStruct, err := archStruct.GetImageType(itLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + reflect.DeepEqual(itStruct.BuildPackages(), buildPackages[archLabel]) + } + } +} diff --git a/internal/distro/fedora31/distro_test.go b/internal/distro/fedora31/distro_test.go index ad74630db..2b2bf6d2a 100644 --- a/internal/distro/fedora31/distro_test.go +++ b/internal/distro/fedora31/distro_test.go @@ -2,6 +2,7 @@ package fedora31_test import ( "github.com/osbuild/osbuild-composer/internal/distro/fedora31" + "reflect" "testing" ) @@ -92,3 +93,47 @@ func TestFilenameFromType(t *testing.T) { }) } } + +func TestImageType_BuildPackages(t *testing.T) { + x8664BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "grub2-pc", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + aarch64BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + buildPackages := map[string][]string{ + "x86_64": x8664BuildPackages, + "aarch64": aarch64BuildPackages, + } + d := fedora31.New() + for _, archLabel := range d.ListArchs() { + archStruct, err := d.GetArch(archLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + for _, itLabel := range archStruct.ListImageTypes() { + itStruct, err := archStruct.GetImageType(itLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + reflect.DeepEqual(itStruct.BuildPackages(), buildPackages[archLabel]) + } + } +} diff --git a/internal/distro/fedora32/distro_test.go b/internal/distro/fedora32/distro_test.go index 8aa8e0c94..40ad6f0a3 100644 --- a/internal/distro/fedora32/distro_test.go +++ b/internal/distro/fedora32/distro_test.go @@ -2,6 +2,7 @@ package fedora32_test import ( "github.com/osbuild/osbuild-composer/internal/distro/fedora32" + "reflect" "testing" ) @@ -92,3 +93,47 @@ func TestFilenameFromType(t *testing.T) { }) } } + +func TestImageType_BuildPackages(t *testing.T) { + x8664BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "grub2-pc", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + aarch64BuildPackages := []string{ + "dnf", + "dosfstools", + "e2fsprogs", + "policycoreutils", + "qemu-img", + "systemd", + "tar", + "xz", + } + buildPackages := map[string][]string{ + "x86_64": x8664BuildPackages, + "aarch64": aarch64BuildPackages, + } + d := fedora32.New() + for _, archLabel := range d.ListArchs() { + archStruct, err := d.GetArch(archLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + for _, itLabel := range archStruct.ListImageTypes() { + itStruct, err := archStruct.GetImageType(itLabel) + if err != nil { + t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err) + continue + } + reflect.DeepEqual(itStruct.BuildPackages(), buildPackages[archLabel]) + } + } +}