Extend the "Test Distro" definition and modify affected tests
Extend the "Test Distro" implementation and definition to contain two architectures and make the second architecture contain two image types. Add New2() function returning another "Test Distro". Modify the `internal/store` unit tests to reflect changes done to the "Test Distro". Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
8dcf859473
commit
e5dd45b71c
3 changed files with 199 additions and 66 deletions
|
|
@ -3,6 +3,7 @@ package test_distro
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
|
|
@ -10,49 +11,121 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
)
|
||||
|
||||
type TestDistro struct{}
|
||||
type TestArch struct{}
|
||||
type TestImageType struct{}
|
||||
type TestDistro struct {
|
||||
name string
|
||||
modulePlatformID string
|
||||
arches map[string]distro.Arch
|
||||
}
|
||||
|
||||
const name = "test-distro"
|
||||
const modulePlatformID = "platform:test"
|
||||
type TestArch struct {
|
||||
distribution *TestDistro
|
||||
name string
|
||||
imageTypes map[string]distro.ImageType
|
||||
}
|
||||
|
||||
type TestImageType struct {
|
||||
architecture *TestArch
|
||||
name string
|
||||
}
|
||||
|
||||
const (
|
||||
TestDistroName = "test-distro"
|
||||
TestDistro2Name = "test-distro-2"
|
||||
TestDistroModulePlatformID = "platform:test"
|
||||
TestDistro2ModulePlatformID = "platform:test-2"
|
||||
|
||||
TestArchName = "test_arch"
|
||||
TestArch2Name = "test_arch2"
|
||||
|
||||
TestImageTypeName = "test_type"
|
||||
TestImageType2Name = "test_type2"
|
||||
)
|
||||
|
||||
// TestDistro
|
||||
|
||||
func (d *TestDistro) Name() string {
|
||||
return d.name
|
||||
}
|
||||
|
||||
func (d *TestDistro) ModulePlatformID() string {
|
||||
return d.modulePlatformID
|
||||
}
|
||||
|
||||
func (d *TestDistro) ListArches() []string {
|
||||
return []string{"test_arch"}
|
||||
}
|
||||
|
||||
func (a *TestArch) Distro() distro.Distro {
|
||||
return &TestDistro{}
|
||||
}
|
||||
|
||||
func (t *TestImageType) Arch() distro.Arch {
|
||||
return &TestArch{}
|
||||
archs := make([]string, 0, len(d.arches))
|
||||
for name := range d.arches {
|
||||
archs = append(archs, name)
|
||||
}
|
||||
sort.Strings(archs)
|
||||
return archs
|
||||
}
|
||||
|
||||
func (d *TestDistro) GetArch(arch string) (distro.Arch, error) {
|
||||
if arch != "test_arch" {
|
||||
a, exists := d.arches[arch]
|
||||
if !exists {
|
||||
return nil, errors.New("invalid arch: " + arch)
|
||||
}
|
||||
return &TestArch{}, nil
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (d *TestDistro) addArches(arches ...*TestArch) {
|
||||
if d.arches == nil {
|
||||
d.arches = map[string]distro.Arch{}
|
||||
}
|
||||
|
||||
for _, a := range arches {
|
||||
a.distribution = d
|
||||
d.arches[a.Name()] = a
|
||||
}
|
||||
}
|
||||
|
||||
// TestArch
|
||||
|
||||
func (a *TestArch) Name() string {
|
||||
return "test_arch"
|
||||
return a.name
|
||||
}
|
||||
|
||||
func (a *TestArch) Distro() distro.Distro {
|
||||
return a.distribution
|
||||
}
|
||||
|
||||
func (a *TestArch) ListImageTypes() []string {
|
||||
return []string{"test_type"}
|
||||
formats := make([]string, 0, len(a.imageTypes))
|
||||
for name := range a.imageTypes {
|
||||
formats = append(formats, name)
|
||||
}
|
||||
sort.Strings(formats)
|
||||
return formats
|
||||
}
|
||||
|
||||
func (a *TestArch) GetImageType(imageType string) (distro.ImageType, error) {
|
||||
if imageType != "test_type" {
|
||||
t, exists := a.imageTypes[imageType]
|
||||
if !exists {
|
||||
return nil, errors.New("invalid image type: " + imageType)
|
||||
}
|
||||
return &TestImageType{}, nil
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (a *TestArch) addImageTypes(imageTypes ...TestImageType) {
|
||||
if a.imageTypes == nil {
|
||||
a.imageTypes = map[string]distro.ImageType{}
|
||||
}
|
||||
for idx := range imageTypes {
|
||||
it := imageTypes[idx]
|
||||
it.architecture = a
|
||||
a.imageTypes[it.Name()] = &it
|
||||
}
|
||||
}
|
||||
|
||||
// TestImageType
|
||||
|
||||
func (t *TestImageType) Name() string {
|
||||
return "test_type"
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *TestImageType) Arch() distro.Arch {
|
||||
return t.architecture
|
||||
}
|
||||
|
||||
func (t *TestImageType) Filename() string {
|
||||
|
|
@ -95,22 +168,48 @@ func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.Ima
|
|||
)
|
||||
}
|
||||
|
||||
func New() *TestDistro {
|
||||
return &TestDistro{}
|
||||
}
|
||||
|
||||
func (d *TestDistro) Name() string {
|
||||
return name
|
||||
}
|
||||
|
||||
func (d *TestDistro) ModulePlatformID() string {
|
||||
return modulePlatformID
|
||||
}
|
||||
|
||||
func (d *TestDistro) FilenameFromType(outputFormat string) (string, string, error) {
|
||||
if outputFormat == "test_format" {
|
||||
return "test.img", "application/x-test", nil
|
||||
// newTestDistro returns a new instance of TestDistro with the
|
||||
// given name and modulePlatformID.
|
||||
//
|
||||
// It contains two architectures "test_arch" and "test_arch2".
|
||||
// "test_arch" contains one image type "test_type".
|
||||
// "test_arch2" contains two image types "test_type" and "test_type2".
|
||||
func newTestDistro(name, modulePlatformID string) *TestDistro {
|
||||
td := TestDistro{
|
||||
name: name,
|
||||
modulePlatformID: modulePlatformID,
|
||||
}
|
||||
|
||||
return "", "", errors.New("invalid output format: " + outputFormat)
|
||||
ta1 := TestArch{
|
||||
name: TestArchName,
|
||||
}
|
||||
|
||||
ta2 := TestArch{
|
||||
name: TestArch2Name,
|
||||
}
|
||||
|
||||
it1 := TestImageType{
|
||||
name: TestImageTypeName,
|
||||
}
|
||||
|
||||
it2 := TestImageType{
|
||||
name: TestImageType2Name,
|
||||
}
|
||||
|
||||
ta1.addImageTypes(it1)
|
||||
ta2.addImageTypes(it1, it2)
|
||||
|
||||
td.addArches(&ta1, &ta2)
|
||||
|
||||
return &td
|
||||
}
|
||||
|
||||
// New returns new instance of TestDistro named "test-distro".
|
||||
func New() *TestDistro {
|
||||
return newTestDistro(TestDistroName, TestDistroModulePlatformID)
|
||||
}
|
||||
|
||||
// New2 returns new instance of TestDistro named "test-distro-2".
|
||||
func New2() *TestDistro {
|
||||
return newTestDistro(TestDistro2Name, TestDistro2ModulePlatformID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ func Test_imageTypeToCompatString(t *testing.T) {
|
|||
type args struct {
|
||||
input distro.ImageType
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
|
|
@ -42,9 +47,9 @@ func Test_imageTypeToCompatString(t *testing.T) {
|
|||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
input: &test_distro.TestImageType{},
|
||||
input: testImageType,
|
||||
},
|
||||
want: "test_type",
|
||||
want: test_distro.TestImageTypeName,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
@ -62,6 +67,11 @@ func Test_imageTypeFromCompatString(t *testing.T) {
|
|||
input string
|
||||
arch distro.Arch
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
|
|
@ -70,16 +80,16 @@ func Test_imageTypeFromCompatString(t *testing.T) {
|
|||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
input: "test_type",
|
||||
arch: &test_distro.TestArch{},
|
||||
input: test_distro.TestImageTypeName,
|
||||
arch: testArch,
|
||||
},
|
||||
want: &test_distro.TestImageType{},
|
||||
want: testImageType,
|
||||
},
|
||||
{
|
||||
name: "invalid mapping",
|
||||
args: args{
|
||||
input: "foo",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
},
|
||||
want: nil,
|
||||
},
|
||||
|
|
@ -87,7 +97,7 @@ func Test_imageTypeFromCompatString(t *testing.T) {
|
|||
name: "invalid distro name",
|
||||
args: args{
|
||||
input: "test_type_invalid",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
},
|
||||
want: nil,
|
||||
},
|
||||
|
|
@ -179,6 +189,10 @@ func Test_newStoreFromV0(t *testing.T) {
|
|||
storeStruct storeV0
|
||||
arch distro.Arch
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
|
|
@ -188,9 +202,9 @@ func Test_newStoreFromV0(t *testing.T) {
|
|||
name: "empty",
|
||||
args: args{
|
||||
storeStruct: storeV0{},
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
},
|
||||
want: New(nil, &test_distro.TestArch{}, nil),
|
||||
want: New(nil, testArch, nil),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
@ -981,6 +995,10 @@ func Test_newComposeV0(t *testing.T) {
|
|||
{Name: "tmux", Version: "*"}},
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
compose Compose
|
||||
|
|
@ -992,7 +1010,7 @@ func Test_newComposeV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1067,6 +1085,10 @@ func Test_newComposeFromV0(t *testing.T) {
|
|||
{Name: "tmux", Version: "*"}},
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
compose composeV0
|
||||
|
|
@ -1077,20 +1099,20 @@ func Test_newComposeFromV0(t *testing.T) {
|
|||
{
|
||||
name: "empty",
|
||||
compose: composeV0{},
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
want: Compose{},
|
||||
errOk: true,
|
||||
},
|
||||
{
|
||||
name: "qcow2 compose",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
errOk: false,
|
||||
compose: composeV0{
|
||||
Blueprint: &bp,
|
||||
ImageBuilds: []imageBuildV0{
|
||||
{
|
||||
ID: 0,
|
||||
ImageType: "test_type",
|
||||
ImageType: test_distro.TestImageTypeName,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1119,7 +1141,7 @@ func Test_newComposeFromV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1169,6 +1191,10 @@ func Test_newComposesV0(t *testing.T) {
|
|||
{Name: "tmux", Version: "*"}},
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
composes map[uuid.UUID]Compose
|
||||
|
|
@ -1181,7 +1207,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1209,7 +1235,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1240,7 +1266,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
ImageBuilds: []imageBuildV0{
|
||||
imageBuildV0{
|
||||
ID: 0,
|
||||
ImageType: "test_type",
|
||||
ImageType: test_distro.TestImageTypeName,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1271,7 +1297,7 @@ func Test_newComposesV0(t *testing.T) {
|
|||
ImageBuilds: []imageBuildV0{
|
||||
imageBuildV0{
|
||||
ID: 0,
|
||||
ImageType: "test_type",
|
||||
ImageType: test_distro.TestImageTypeName,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1318,6 +1344,10 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
{Name: "tmux", Version: "*"}},
|
||||
}
|
||||
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arch distro.Arch
|
||||
|
|
@ -1326,13 +1356,13 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
name: "empty",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
composes: composesV0{},
|
||||
want: make(map[uuid.UUID]Compose),
|
||||
},
|
||||
{
|
||||
name: "two composes",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
composes: composesV0{
|
||||
uuid.MustParse("f53b49c0-d321-447e-8ab8-6e827891e3f0"): {
|
||||
Blueprint: &bp,
|
||||
|
|
@ -1400,7 +1430,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1429,7 +1459,7 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
Blueprint: &bp,
|
||||
ImageBuild: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1467,6 +1497,10 @@ func Test_newComposesFromV0(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_newImageBuildFromV0(t *testing.T) {
|
||||
testDistro := test_distro.New()
|
||||
testArch, _ := testDistro.GetArch(test_distro.TestArchName)
|
||||
testImageType, _ := testArch.GetImageType(test_distro.TestImageTypeName)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arch distro.Arch
|
||||
|
|
@ -1476,18 +1510,18 @@ func Test_newImageBuildFromV0(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
name: "empty",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
errOk: true,
|
||||
ib: imageBuildV0{},
|
||||
want: ImageBuild{},
|
||||
},
|
||||
{
|
||||
name: "qcow2 image build",
|
||||
arch: &test_distro.TestArch{},
|
||||
arch: testArch,
|
||||
errOk: false,
|
||||
ib: imageBuildV0{
|
||||
ID: 0,
|
||||
ImageType: "test_type",
|
||||
ImageType: test_distro.TestImageTypeName,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
@ -1512,7 +1546,7 @@ func Test_newImageBuildFromV0(t *testing.T) {
|
|||
},
|
||||
want: ImageBuild{
|
||||
ID: 0,
|
||||
ImageType: &test_distro.TestImageType{},
|
||||
ImageType: testImageType,
|
||||
Manifest: []byte("JSON MANIFEST GOES HERE"),
|
||||
Targets: []*target.Target{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ func (suite *storeTest) SetupSuite() {
|
|||
}}
|
||||
suite.myPackageSpec = []rpmmd.PackageSpec{rpmmd.PackageSpec{}}
|
||||
suite.myDistro = test_distro.New()
|
||||
suite.myArch, _ = suite.myDistro.GetArch("test_arch")
|
||||
suite.myImageType, _ = suite.myArch.GetImageType("test_type")
|
||||
suite.myArch, _ = suite.myDistro.GetArch(test_distro.TestArchName)
|
||||
suite.myImageType, _ = suite.myArch.GetImageType(test_distro.TestImageTypeName)
|
||||
suite.myManifest, _ = suite.myImageType.Manifest(&suite.myCustomizations, suite.myImageOptions, suite.myRepoConfig, nil, 0)
|
||||
suite.mySourceConfig = SourceConfig{
|
||||
Name: "testSourceConfig",
|
||||
|
|
@ -115,7 +115,7 @@ func (suite *storeTest) SetupTest() {
|
|||
tmpDir, err := ioutil.TempDir("/tmp", "osbuild-composer-test-")
|
||||
suite.NoError(err)
|
||||
distro := test_distro.New()
|
||||
arch, err := distro.GetArch("test_arch")
|
||||
arch, err := distro.GetArch(test_distro.TestArchName)
|
||||
suite.NoError(err)
|
||||
suite.dir = tmpDir
|
||||
suite.myStore = New(&suite.dir, arch, nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue