Skip to content

Commit

Permalink
osbuild: add minimal json test for the erofs stage
Browse files Browse the repository at this point in the history
This commit adds a minimal json test for the erof stage to ensure
that the json struct tags are correct and to also in the
"test-as-documentation" sense to hint at what the json looks like.
  • Loading branch information
mvo5 committed Jan 14, 2025
1 parent b1dbc1c commit afcde39
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions pkg/osbuild/erofs_stage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package osbuild_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/osbuild"
)

func TestErofStageJsonMinimal(t *testing.T) {
expectedJson := `{
"type": "org.osbuild.erofs",
"inputs": {
"tree": {
"type": "org.osbuild.tree",
"origin": "org.osbuild.pipeline",
"references": [
"name:input-pipeline"
]
}
},
"options": {
"filename": "foo.ero"
}
}`

opts := &osbuild.ErofsStageOptions{
Filename: "foo.ero",
}
stage := osbuild.NewErofsStage(opts, "input-pipeline")
require.NotNil(t, stage)

json, err := json.MarshalIndent(stage, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), expectedJson)
}

func TestErofStageJsonFull(t *testing.T) {
expectedJson := `{
"type": "org.osbuild.erofs",
"inputs": {
"tree": {
"type": "org.osbuild.tree",
"origin": "org.osbuild.pipeline",
"references": [
"name:input-pipeline"
]
}
},
"options": {
"filename": "foo.ero",
"compression": {
"method": "lz4hc",
"level": 9
},
"options": [
"all-fragments",
"dedupe"
],
"cluster-size": 131072
}
}`

opts := &osbuild.ErofsStageOptions{
Filename: "foo.ero",
Compression: &osbuild.ErofsCompression{
Method: "lz4hc",
Level: common.ToPtr(9),
},
ExtendedOptions: []string{"all-fragments", "dedupe"},
ClusterSize: common.ToPtr(131072),
}
stage := osbuild.NewErofsStage(opts, "input-pipeline")
require.NotNil(t, stage)

json, err := json.MarshalIndent(stage, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), expectedJson)
}

0 comments on commit afcde39

Please sign in to comment.