-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osbuild: add minimal json test for the erofs stage
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
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |