blueprint: add unit tests for ex4 output type

Also fix a bug where the RawFs assembler was not correctly unmarshaled.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-21 17:29:38 +02:00 committed by Lars Karlitski
parent 32be0d05cb
commit 09ac84926e
4 changed files with 174 additions and 0 deletions

View file

@ -83,6 +83,11 @@ func TestBlueprint_ToPipeline(t *testing.T) {
args: args{"ami"},
want: "pipelines/ami_empty_blueprint.json",
},
{
name: "ext4",
args: args{"ext4-filesystem"},
want: "pipelines/ext4_empty_blueprint.json",
},
{
name: "live-iso",
args: args{"live-iso"},
@ -168,6 +173,12 @@ func TestFilenameFromType(t *testing.T) {
want: "image.ami",
want1: "application/x-qemu-disk",
},
{
name: "ext4",
args: args{"ext4-filesystem"},
want: "image.img",
want1: "application/octet-stream",
},
{
name: "live-iso",
args: args{"live-iso"},

View file

@ -0,0 +1,81 @@
package blueprint
import (
"encoding/json"
"io/ioutil"
"reflect"
"testing"
"github.com/osbuild/osbuild-composer/internal/pipeline"
)
func Test_ext4Output_translate(t *testing.T) {
type args struct {
b *Blueprint
}
tests := []struct {
name string
t *ext4Output
args args
want string
}{
{
name: "empty-blueprint",
t: &ext4Output{},
args: args{&Blueprint{}},
want: "pipelines/ext4_empty_blueprint.json",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
file, _ := ioutil.ReadFile(tt.want)
var want pipeline.Pipeline
json.Unmarshal([]byte(file), &want)
if got := tt.t.translate(tt.args.b); !reflect.DeepEqual(got, &want) {
t.Errorf("ext4Output.translate() = %v, want %v", got, &want)
}
})
}
}
func Test_ext4Output_getName(t *testing.T) {
tests := []struct {
name string
t *ext4Output
want string
}{
{
name: "basic",
t: &ext4Output{},
want: "image.img",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.getName(); got != tt.want {
t.Errorf("ext4Output.getName() = %v, want %v", got, tt.want)
}
})
}
}
func Test_ext4Output_getMime(t *testing.T) {
tests := []struct {
name string
t *ext4Output
want string
}{
{
name: "basic",
t: &ext4Output{},
want: "application/octet-stream",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.getMime(); got != tt.want {
t.Errorf("ext4Output.getMime() = %v, want %v", got, tt.want)
}
})
}
}

View file

@ -0,0 +1,80 @@
{
"build": {
"stages": [
{
"name": "org.osbuild.dnf",
"options": {
"repos": [
{
"metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
"gpgkey": "F1D8 EC98 F241 AAF2 0DF6 9420 EF3C 111F CFC6 59B9",
"checksum": "sha256:9f596e18f585bee30ac41c11fb11a83ed6b11d5b341c1cb56ca4015d7717cb97"
}
],
"packages": [
"dnf",
"e2fsprogs",
"policycoreutils",
"qemu-img",
"systemd",
"grub2-pc",
"tar"
],
"releasever": "30",
"basearch": "x86_64"
}
}
]
},
"stages": [
{
"name": "org.osbuild.dnf",
"options": {
"repos": [
{
"metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
"gpgkey": "F1D8 EC98 F241 AAF2 0DF6 9420 EF3C 111F CFC6 59B9",
"checksum": "sha256:9f596e18f585bee30ac41c11fb11a83ed6b11d5b341c1cb56ca4015d7717cb97"
}
],
"packages": [
"@Core",
"chrony",
"kernel",
"selinux-policy-targeted",
"grub2-pc",
"spice-vdagent",
"qemu-guest-agent",
"xen-libs",
"langpacks-en"
],
"releasever": "30",
"basearch": "x86_64"
}
},
{
"name": "org.osbuild.fix-bls",
"options": {}
},
{
"name": "org.osbuild.locale",
"options": {
"language": "en_US"
}
},
{
"name": "org.osbuild.selinux",
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
}
],
"assembler": {
"name": "org.osbuild.rawfs",
"options": {
"filename": "image.img",
"root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac",
"size": 3221225472
}
}
}

View file

@ -36,6 +36,8 @@ func (assembler *Assembler) UnmarshalJSON(data []byte) error {
options = new(TarAssemblerOptions)
case "org.osbuild.qemu":
options = new(QEMUAssemblerOptions)
case "org.osbuild.rawfs":
options = new(RawFSAssemblerOptions)
default:
return errors.New("unexpected assembler name")
}