distro: test manifest version detection
This commit is contained in:
parent
39e646ae68
commit
dce3e1de9e
1 changed files with 80 additions and 0 deletions
|
|
@ -3,8 +3,10 @@ package distro_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||||
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
|
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
|
||||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDistro_Manifest(t *testing.T) {
|
func TestDistro_Manifest(t *testing.T) {
|
||||||
|
|
@ -16,3 +18,81 @@ func TestDistro_Manifest(t *testing.T) {
|
||||||
distroregistry.NewDefault(),
|
distroregistry.NewDefault(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
v1manifests = []string{
|
||||||
|
`{}`,
|
||||||
|
`
|
||||||
|
{
|
||||||
|
"sources": {
|
||||||
|
"org.osbuild.files": {
|
||||||
|
"urls": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pipeline": {
|
||||||
|
"build": {
|
||||||
|
"pipeline": {
|
||||||
|
"stages": []
|
||||||
|
},
|
||||||
|
"runner": "org.osbuild.rhel84"
|
||||||
|
},
|
||||||
|
"stages": [],
|
||||||
|
"assembler": {
|
||||||
|
"name": "org.osbuild.qemu",
|
||||||
|
"options": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
v2manifests = []string{
|
||||||
|
`{"version": "2"}`,
|
||||||
|
`
|
||||||
|
{
|
||||||
|
"version": "2",
|
||||||
|
"pipelines": [
|
||||||
|
{
|
||||||
|
"name": "build",
|
||||||
|
"runner": "org.osbuild.rhel84",
|
||||||
|
"stages": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sources": {
|
||||||
|
"org.osbuild.curl": {
|
||||||
|
"items": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDistro_Version(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
expectedVersion := "1"
|
||||||
|
for idx, rawManifest := range v1manifests {
|
||||||
|
manifest := distro.Manifest(rawManifest)
|
||||||
|
detectedVersion, err := manifest.Version()
|
||||||
|
require.NoError(err, "Could not detect Manifest version for %d: %v", idx, err)
|
||||||
|
require.Equal(expectedVersion, detectedVersion, "in manifest %d", idx)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedVersion = "2"
|
||||||
|
for idx, rawManifest := range v2manifests {
|
||||||
|
manifest := distro.Manifest(rawManifest)
|
||||||
|
detectedVersion, err := manifest.Version()
|
||||||
|
require.NoError(err, "Could not detect Manifest version for %d: %v", idx, err)
|
||||||
|
require.Equal(expectedVersion, detectedVersion, "in manifest %d", idx)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
manifest := distro.Manifest("")
|
||||||
|
_, err := manifest.Version()
|
||||||
|
require.Error(err, "Empty manifest did not return an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
manifest := distro.Manifest("{")
|
||||||
|
_, err := manifest.Version()
|
||||||
|
require.Error(err, "Invalid manifest did not return an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue