WithSingleDistro() doesn't follow go's naming convention for creating objects (New*). Rename it to NewRegistry() and rename the old NewRegistry() to NewDefaultRegistry(). The idea is that NewRegistry() can be used to create full Registry objects from outside the package. NewDefaultRegistry() is a convenience function that creates a Registry with all known distros.
113 lines
2.3 KiB
Go
113 lines
2.3 KiB
Go
package rhel82_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
|
)
|
|
|
|
func TestListOutputFormats(t *testing.T) {
|
|
want := []string{
|
|
"ami",
|
|
"ext4-filesystem",
|
|
"openstack",
|
|
"partitioned-disk",
|
|
"qcow2",
|
|
"tar",
|
|
"vhd",
|
|
"vmdk",
|
|
}
|
|
|
|
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
|
rhel82 := distros.GetDistro("rhel-8.2")
|
|
if got := rhel82.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
|
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestFilenameFromType(t *testing.T) {
|
|
type args struct {
|
|
outputFormat string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
want1 string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "ami",
|
|
args: args{"ami"},
|
|
want: "image.raw.xz",
|
|
want1: "application/octet-stream",
|
|
},
|
|
{
|
|
name: "ext4",
|
|
args: args{"ext4-filesystem"},
|
|
want: "filesystem.img",
|
|
want1: "application/octet-stream",
|
|
},
|
|
{
|
|
name: "openstack",
|
|
args: args{"openstack"},
|
|
want: "disk.qcow2",
|
|
want1: "application/x-qemu-disk",
|
|
},
|
|
{
|
|
name: "partitioned-disk",
|
|
args: args{"partitioned-disk"},
|
|
want: "disk.img",
|
|
want1: "application/octet-stream",
|
|
},
|
|
{
|
|
name: "qcow2",
|
|
args: args{"qcow2"},
|
|
want: "disk.qcow2",
|
|
want1: "application/x-qemu-disk",
|
|
},
|
|
{
|
|
name: "tar",
|
|
args: args{"tar"},
|
|
want: "root.tar.xz",
|
|
want1: "application/x-tar",
|
|
},
|
|
{
|
|
name: "vhd",
|
|
args: args{"vhd"},
|
|
want: "disk.vhd",
|
|
want1: "application/x-vhd",
|
|
},
|
|
{
|
|
name: "vmdk",
|
|
args: args{"vmdk"},
|
|
want: "disk.vmdk",
|
|
want1: "application/x-vmdk",
|
|
},
|
|
{
|
|
name: "invalid-output-type",
|
|
args: args{"foobar"},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
distros := distro.NewDefaultRegistry([]string{"../../../"})
|
|
rhel82 := distros.GetDistro("rhel-8.2")
|
|
got, got1, err := rhel82.FilenameFromType(tt.args.outputFormat)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !tt.wantErr {
|
|
if got != tt.want {
|
|
t.Errorf("FilenameFromType() got = %v, want %v", got, tt.want)
|
|
}
|
|
if got1 != tt.want1 {
|
|
t.Errorf("FilenameFromType() got1 = %v, want %v", got1, tt.want1)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|