debian-forge-composer/internal/distro/test/distro.go
Jacob Kozol abb5469b30 distro: get proper image size from distro
When a user does not define the image size for a compose the default
image size of that image type is used. In order to properly store the
compose's image size even if the default is used the store calls the
distro function GetSizeForOutputType. This function accepts an output
format and image size. If the image size is 0 then the default
value for the output format will be returned. Also, for vhd images the
size must be rounded. This is now handled in the distro function instead
of the api.
2020-02-07 14:49:15 +01:00

59 lines
1.5 KiB
Go

package test
import (
"errors"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/pipeline"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
type TestDistro struct{}
const Name = "test-distro"
func New() *TestDistro {
return &TestDistro{}
}
func (d *TestDistro) Name() string {
return Name
}
func (d *TestDistro) Repositories(arch string) []rpmmd.RepoConfig {
return []rpmmd.RepoConfig{
{
Id: "test-id",
Name: "Test Name",
BaseURL: "http://example.com/test/os/" + arch,
},
}
}
func (d *TestDistro) ListOutputFormats() []string {
return []string{"test_format"}
}
func (d *TestDistro) FilenameFromType(outputFormat string) (string, string, error) {
if outputFormat == "test_format" {
return "test.img", "application/x-test", nil
} else {
return "", "", errors.New("invalid output format: " + outputFormat)
}
}
func (r *TestDistro) GetSizeForOutputType(outputFormat string, size uint64) uint64 {
return 0
}
func (d *TestDistro) Pipeline(b *blueprint.Blueprint, additionalRepos []rpmmd.RepoConfig, checksums map[string]string, outputArch, outputFormat string, size uint64) (*pipeline.Pipeline, error) {
if outputFormat == "test_output" && outputArch == "test_arch" {
return &pipeline.Pipeline{}, nil
} else {
return nil, errors.New("invalid output format or arch: " + outputFormat + " @ " + outputArch)
}
}
func (d *TestDistro) Runner() string {
return "org.osbuild.test"
}