osbuild: test result conversions
Moved and adapted tests from osbuild1 to osbuild2. Moved test data from osbuild1 to osbuild2. Added conversion tests for v1 to v2. Added full v2 result raw data from successful build. Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
parent
b7bab25e73
commit
dc0e3dea92
4 changed files with 8047 additions and 790 deletions
|
|
@ -3,7 +3,6 @@ package osbuild1
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -71,83 +70,6 @@ func TestUnmarshal(t *testing.T) {
|
|||
assert.Empty(t, package2.SigGPG)
|
||||
}
|
||||
|
||||
func TestUnmarshalV1Success(t *testing.T) {
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v1ResultSuccess), &result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.True(t, result.Success)
|
||||
|
||||
assert.True(t, result.Build.Success)
|
||||
assert.Len(t, result.Build.Stages, 2)
|
||||
assert.True(t, result.Build.Stages[1].Success)
|
||||
assert.Equal(t, "org.osbuild.rpm", result.Build.Stages[0].Name)
|
||||
|
||||
assert.Len(t, result.Stages, 11)
|
||||
assert.True(t, result.Stages[10].Success)
|
||||
assert.Equal(t, result.Stages[0].Name, "org.osbuild.rpm")
|
||||
|
||||
assert.True(t, result.Assembler.Success)
|
||||
assert.Equal(t, result.Assembler.Name, "org.osbuild.qemu")
|
||||
}
|
||||
|
||||
func TestUnmarshalV1Failure(t *testing.T) {
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v1ResultFailure), &result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.False(t, result.Success)
|
||||
|
||||
assert.True(t, result.Build.Success)
|
||||
assert.Len(t, result.Build.Stages, 2)
|
||||
assert.True(t, result.Build.Stages[1].Success)
|
||||
assert.Equal(t, "org.osbuild.rpm", result.Build.Stages[0].Name)
|
||||
|
||||
assert.Len(t, result.Stages, 9)
|
||||
assert.False(t, result.Stages[8].Success)
|
||||
assert.Equal(t, result.Stages[0].Name, "org.osbuild.rpm")
|
||||
|
||||
assert.Nil(t, result.Assembler)
|
||||
}
|
||||
|
||||
func TestUnmarshalV2Success(t *testing.T) {
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v2ResultSuccess), &result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.True(t, result.Success)
|
||||
|
||||
assert.Len(t, result.Stages, 16)
|
||||
assert.True(t, result.Stages[15].Success)
|
||||
assert.NotEmpty(t, result.Stages[0].Name)
|
||||
|
||||
// check metadata
|
||||
for _, stage := range result.Stages {
|
||||
if strings.HasSuffix(stage.Name, "org.osbuild.rpm") {
|
||||
rpmMd, convOk := stage.Metadata.(RPMStageMetadata)
|
||||
assert.True(t, convOk)
|
||||
assert.Greater(t, len(rpmMd.Packages), 0)
|
||||
} else if strings.HasSuffix(stage.Name, "org.osbuild.ostree.commit") {
|
||||
commitMd, convOk := stage.Metadata.(OSTreeCommitStageMetadata)
|
||||
assert.True(t, convOk)
|
||||
assert.NotEmpty(t, commitMd.Compose.Ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalV2Failure(t *testing.T) {
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v2ResultFailure), &result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.False(t, result.Success)
|
||||
|
||||
assert.Len(t, result.Stages, 7)
|
||||
assert.True(t, result.Stages[5].Success)
|
||||
assert.False(t, result.Stages[6].Success)
|
||||
assert.NotEmpty(t, result.Stages[0].Name)
|
||||
}
|
||||
|
||||
func TestWriteFull(t *testing.T) {
|
||||
|
||||
const testOptions = `{"msg": "test"}`
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -26,3 +26,176 @@ func TestStageResult_UnmarshalJSON(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(fullResultRaw), &result)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.True(result.Success)
|
||||
|
||||
assert.Equal(len(result.Log), 4)
|
||||
for _, plName := range []string{"build", "image", "os", "qcow2"} {
|
||||
assert.Contains(result.Log, plName)
|
||||
for _, stage := range result.Log[plName] {
|
||||
assert.True(stage.Success)
|
||||
}
|
||||
}
|
||||
assert.Equal(len(result.Metadata), 2)
|
||||
|
||||
pipelinePackageCount := map[string]int{
|
||||
"build": 254,
|
||||
"os": 449,
|
||||
}
|
||||
for _, plName := range []string{"build", "os"} {
|
||||
assert.Contains(result.Metadata, plName)
|
||||
for stageType, stageMetadata := range result.Metadata[plName] {
|
||||
if stageType == "org.osbuild.rpm" {
|
||||
rpmMd, convOk := stageMetadata.(*RPMStageMetadata)
|
||||
assert.True(convOk)
|
||||
assert.Len(rpmMd.Packages, pipelinePackageCount[plName])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalV1Success(t *testing.T) {
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v1ResultSuccess), &result)
|
||||
|
||||
assert := assert.New(t)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.True(result.Success)
|
||||
|
||||
pipelineStageCount := map[string]int{
|
||||
"build": 2,
|
||||
"os": 11,
|
||||
"assembler": 1,
|
||||
}
|
||||
assert.Len(result.Log, len(pipelineStageCount))
|
||||
for name, stageCount := range pipelineStageCount {
|
||||
assert.Contains(result.Log, name)
|
||||
assert.Len(result.Log[name], stageCount)
|
||||
for _, stage := range result.Log[name] {
|
||||
assert.True(stage.Success)
|
||||
}
|
||||
}
|
||||
|
||||
buildLog := result.Log["build"]
|
||||
assert.Equal("org.osbuild.rpm", buildLog[0].Type)
|
||||
|
||||
osLog := result.Log["os"]
|
||||
assert.Equal(osLog[0].Type, "org.osbuild.rpm")
|
||||
|
||||
assemblerLog := result.Log["assembler"]
|
||||
assert.Equal(assemblerLog[0].Type, "org.osbuild.qemu")
|
||||
|
||||
for _, plName := range []string{"build", "os"} {
|
||||
assert.Contains(result.Metadata, plName)
|
||||
for stageType, stageMetadata := range result.Metadata[plName] {
|
||||
if stageType == "org.osbuild.rpm" {
|
||||
rpmMd, convOk := stageMetadata.(*RPMStageMetadata)
|
||||
assert.True(convOk)
|
||||
assert.Len(rpmMd.Packages, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalV1Failure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v1ResultFailure), &result)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.False(result.Success)
|
||||
|
||||
pipelineStageCount := map[string]int{
|
||||
"build": 2,
|
||||
"os": 9,
|
||||
}
|
||||
assert.Len(result.Log, len(pipelineStageCount))
|
||||
for name, stageCount := range pipelineStageCount {
|
||||
assert.Contains(result.Log, name)
|
||||
assert.Len(result.Log[name], stageCount)
|
||||
for idx, stage := range result.Log[name] {
|
||||
// lastStage should be false, all else true
|
||||
lastStage := (name == "os") && (idx == pipelineStageCount["os"]-1)
|
||||
assert.Equal(stage.Success, !lastStage)
|
||||
}
|
||||
}
|
||||
|
||||
buildLog := result.Log["build"]
|
||||
assert.Equal("org.osbuild.rpm", buildLog[0].Type)
|
||||
|
||||
osLog := result.Log["os"]
|
||||
assert.False(osLog[8].Success)
|
||||
assert.Equal(osLog[0].Type, "org.osbuild.rpm")
|
||||
}
|
||||
|
||||
func TestUnmarshalV2Success(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v2ResultSuccess), &result)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.True(result.Success)
|
||||
|
||||
pipelineStageCount := map[string]int{
|
||||
"build": 2,
|
||||
"ostree-tree": 7,
|
||||
"ostree-commit": 2,
|
||||
"container-tree": 4,
|
||||
"assembler": 1,
|
||||
}
|
||||
assert.Len(result.Log, len(pipelineStageCount))
|
||||
for name, stageCount := range pipelineStageCount {
|
||||
assert.Contains(result.Log, name)
|
||||
assert.Len(result.Log[name], stageCount)
|
||||
for _, stage := range result.Log[name] {
|
||||
assert.True(stage.Success)
|
||||
}
|
||||
}
|
||||
|
||||
// check metadata
|
||||
for _, pipeline := range result.Metadata {
|
||||
for stageType, stageMetadata := range pipeline {
|
||||
if stageType == "org.osbuild.rpm" {
|
||||
rpmMd, convOk := stageMetadata.(*RPMStageMetadata)
|
||||
assert.True(convOk)
|
||||
assert.Greater(len(rpmMd.Packages), 0)
|
||||
} else if stageType == "org.osbuild.ostree.commit" {
|
||||
commitMd, convOk := stageMetadata.(*OSTreeCommitStageMetadata)
|
||||
assert.True(convOk)
|
||||
assert.NotEmpty(commitMd.Compose.Ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalV2Failure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var result Result
|
||||
err := json.Unmarshal([]byte(v2ResultFailure), &result)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.False(result.Success)
|
||||
|
||||
pipelineStageCount := map[string]int{
|
||||
"build": 2,
|
||||
"ostree-tree": 5,
|
||||
}
|
||||
assert.Len(result.Log, len(pipelineStageCount))
|
||||
for name, stageCount := range pipelineStageCount {
|
||||
assert.Contains(result.Log, name)
|
||||
assert.Len(result.Log[name], stageCount)
|
||||
for idx, stage := range result.Log[name] {
|
||||
// success of last stage in last pipeline should be 'false' and
|
||||
// 'true' everywhere else (Success == !lastStage)
|
||||
lastStage := (name == "ostree-tree") && (idx == pipelineStageCount["ostree-tree"]-1)
|
||||
assert.Equal(stage.Success, !lastStage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7874
internal/osbuild2/result_test_data.go
Normal file
7874
internal/osbuild2/result_test_data.go
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue