distro: remove unused FilenameFromType() function

This information is now provided only when an architecture is specified,
so it is necessary to first obtain object implementing the Arch interface
then object implementing the ImageType interface and then you can get
the filename and mime type.

Tests are changed accordingly to the new API.
This commit is contained in:
Martin Sehnoutka 2020-03-26 10:14:31 +01:00 committed by Tom Gundersen
parent 2f576e0964
commit 6d2d259e57
12 changed files with 44 additions and 82 deletions

View file

@ -31,11 +31,6 @@ type Distro interface {
// Returns an object representing the given architecture as support
// by this distro.
GetArch(arch string) (Arch, error)
// Returns the canonical filename and MIME type for a given output
// format. `outputFormat` must be one returned by
// TODO: remove when redundant
FilenameFromType(outputFormat string) (string, string, error)
}
// An Arch represents a given distribution's support for a given architecture.

View file

@ -411,13 +411,6 @@ func (r *Fedora30) ModulePlatformID() string {
return modulePlatformID
}
func (r *Fedora30) FilenameFromType(outputFormat string) (string, string, error) {
if output, exists := r.imageTypes[outputFormat]; exists {
return output.name, output.mimeType, nil
}
return "", "", errors.New("invalid output format: " + outputFormat)
}
func sources(packages []rpmmd.PackageSpec) *osbuild.Sources {
files := &osbuild.FilesSource{
URLs: make(map[string]string),

View file

@ -1,9 +1,8 @@
package fedora30_test
import (
"testing"
"github.com/osbuild/osbuild-composer/internal/distro/fedora30"
"testing"
)
func TestFilenameFromType(t *testing.T) {
@ -73,18 +72,21 @@ func TestFilenameFromType(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f30 := fedora30.New()
got, got1, err := f30.FilenameFromType(tt.args.outputFormat)
dist := fedora30.New()
arch, _ := dist.GetArch("x86_64")
imgType, err := arch.GetImageType(tt.args.outputFormat)
if (err != nil) != tt.wantErr {
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, 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("FilenameFromType() got = %v, want %v", got, tt.want)
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
}
}
})

View file

@ -411,13 +411,6 @@ func (r *Fedora31) ModulePlatformID() string {
return modulePlatformID
}
func (r *Fedora31) FilenameFromType(outputFormat string) (string, string, error) {
if output, exists := r.imageTypes[outputFormat]; exists {
return output.name, output.mimeType, nil
}
return "", "", errors.New("invalid output format: " + outputFormat)
}
func sources(packages []rpmmd.PackageSpec) *osbuild.Sources {
files := &osbuild.FilesSource{
URLs: make(map[string]string),

View file

@ -1,9 +1,8 @@
package fedora31_test
import (
"testing"
"github.com/osbuild/osbuild-composer/internal/distro/fedora31"
"testing"
)
func TestFilenameFromType(t *testing.T) {
@ -73,18 +72,21 @@ func TestFilenameFromType(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f31 := fedora31.New()
got, got1, err := f31.FilenameFromType(tt.args.outputFormat)
dist := fedora31.New()
arch, _ := dist.GetArch("x86_64")
imgType, err := arch.GetImageType(tt.args.outputFormat)
if (err != nil) != tt.wantErr {
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, 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("FilenameFromType() got = %v, want %v", got, tt.want)
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
}
}
})

View file

@ -411,13 +411,6 @@ func (r *Fedora32) ModulePlatformID() string {
return modulePlatformID
}
func (r *Fedora32) FilenameFromType(outputFormat string) (string, string, error) {
if output, exists := r.imageTypes[outputFormat]; exists {
return output.name, output.mimeType, nil
}
return "", "", errors.New("invalid output format: " + outputFormat)
}
func sources(packages []rpmmd.PackageSpec) *osbuild.Sources {
files := &osbuild.FilesSource{
URLs: make(map[string]string),

View file

@ -1,9 +1,8 @@
package fedora32_test
import (
"testing"
"github.com/osbuild/osbuild-composer/internal/distro/fedora32"
"testing"
)
func TestFilenameFromType(t *testing.T) {
@ -73,19 +72,21 @@ func TestFilenameFromType(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f32 := fedora32.New()
got, got1, err := f32.FilenameFromType(tt.args.outputFormat)
dist := fedora32.New()
arch, _ := dist.GetArch("x86_64")
imgType, err := arch.GetImageType(tt.args.outputFormat)
if (err != nil) != tt.wantErr {
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, 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("FilenameFromType() got = %v, want %v", got, tt.want)
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
}
}
})

View file

@ -104,11 +104,3 @@ func (d *FedoraTestDistro) Name() string {
func (d *FedoraTestDistro) ModulePlatformID() string {
return modulePlatformID
}
func (d *FedoraTestDistro) FilenameFromType(outputFormat string) (string, string, error) {
if outputFormat == "qcow2" {
return "test.img", "application/x-test", nil
} else {
return "", "", errors.New("invalid output format: " + outputFormat)
}
}

View file

@ -550,13 +550,6 @@ func (r *RHEL81) ModulePlatformID() string {
return modulePlatformID
}
func (r *RHEL81) FilenameFromType(outputFormat string) (string, string, error) {
if output, exists := r.imageTypes[outputFormat]; exists {
return output.name, output.mimeType, nil
}
return "", "", errors.New("invalid output format: " + outputFormat)
}
func sources(packages []rpmmd.PackageSpec) *osbuild.Sources {
files := &osbuild.FilesSource{
URLs: make(map[string]string),

View file

@ -1,9 +1,8 @@
package rhel81_test
import (
"testing"
"github.com/osbuild/osbuild-composer/internal/distro/rhel81"
"testing"
)
func TestFilenameFromType(t *testing.T) {
@ -73,18 +72,21 @@ func TestFilenameFromType(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
el81 := rhel81.New()
got, got1, err := el81.FilenameFromType(tt.args.outputFormat)
dist := rhel81.New()
arch, _ := dist.GetArch("x86_64")
imgType, err := arch.GetImageType(tt.args.outputFormat)
if (err != nil) != tt.wantErr {
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, 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("FilenameFromType() got = %v, want %v", got, tt.want)
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
}
}
})

View file

@ -550,13 +550,6 @@ func (r *RHEL82) ModulePlatformID() string {
return modulePlatformID
}
func (r *RHEL82) FilenameFromType(outputFormat string) (string, string, error) {
if output, exists := r.imageTypes[outputFormat]; exists {
return output.name, output.mimeType, nil
}
return "", "", errors.New("invalid output format: " + outputFormat)
}
func (r *RHEL82) BasePackages(outputFormat string, outputArchitecture string) ([]string, []string, error) {
output, exists := r.imageTypes[outputFormat]
if !exists {

View file

@ -73,18 +73,21 @@ func TestFilenameFromType(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
el82 := rhel82.New()
got, got1, err := el82.FilenameFromType(tt.args.outputFormat)
dist := rhel82.New()
arch, _ := dist.GetArch("x86_64")
imgType, err := arch.GetImageType(tt.args.outputFormat)
if (err != nil) != tt.wantErr {
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, 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("FilenameFromType() got = %v, want %v", got, tt.want)
t.Errorf("ImageType.Filename() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
t.Errorf("ImageType.MIMEType() got1 = %v, want %v", got1, tt.want1)
}
}
})