debian-forge-composer/internal/distro/distro_test.go
Tom Gundersen d33fc5f010 composer: add provisional multi-arch support
The pipeline generation now takes the architecture as an argument.
Currently only x86_64 is supported. The architecture is detected
at start-up, and passed down to each pipeline translation.

For osbuild-pipeline we now requrie the architecture to be passed
in.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-12-11 15:23:24 +01:00

65 lines
2 KiB
Go

package distro_test
import (
"encoding/json"
"io/ioutil"
"reflect"
"testing"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/pipeline"
)
func TestDistro_Pipeline(t *testing.T) {
pipelinePath := "../../test/cases/"
fileInfos, err := ioutil.ReadDir(pipelinePath)
if err != nil {
t.Errorf("Could not read pipelines directory '%s': %v", pipelinePath, err)
}
for _, fileInfo := range fileInfos {
type compose struct {
Distro string `json:"distro"`
Arch string `json:"arch"`
OutputFormat string `json:"output-format"`
Checksums map[string]string `json:"checksums"`
Blueprint *blueprint.Blueprint `json:"blueprint"`
}
var tt struct {
Compose *compose `json:"compose"`
Pipeline *pipeline.Pipeline `json:"pipeline,omitempty"`
}
file, err := ioutil.ReadFile(pipelinePath + fileInfo.Name())
if err != nil {
t.Errorf("Colud not read test-case '%s': %v", fileInfo.Name(), err)
}
err = json.Unmarshal([]byte(file), &tt)
if err != nil {
t.Errorf("Colud not parse test-case '%s': %v", fileInfo.Name(), err)
}
if tt.Compose == nil || tt.Compose.Blueprint == nil {
t.Logf("Skipping '%s'.", fileInfo.Name())
continue
}
t.Run(tt.Compose.OutputFormat, func(t *testing.T) {
d := distro.New(tt.Compose.Distro)
if d == nil {
t.Errorf("unknown distro: %v", tt.Compose.Distro)
return
}
got, err := d.Pipeline(tt.Compose.Blueprint, tt.Compose.Checksums, tt.Compose.Arch, tt.Compose.OutputFormat)
if (err != nil) != (tt.Pipeline == nil) {
t.Errorf("distro.Pipeline() error = %v", err)
return
}
if tt.Pipeline != nil {
if !reflect.DeepEqual(got, tt.Pipeline) {
// Without this the "difference" is just a list of pointers.
gotJson, _ := json.Marshal(got)
fileJson, _ := json.Marshal(tt.Pipeline)
t.Errorf("d.Pipeline() =\n%v,\nwant =\n%v", string(gotJson), string(fileJson))
}
}
})
}
}