From f4715c3b6f65c298030ed73712bc52c9c2af345f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Nov 2024 15:16:14 +0100 Subject: [PATCH] osbuild: add test for NewMkswapStage() --- pkg/osbuild/mkswap_stage_test.go | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/osbuild/mkswap_stage_test.go diff --git a/pkg/osbuild/mkswap_stage_test.go b/pkg/osbuild/mkswap_stage_test.go new file mode 100644 index 0000000000..b914349cc6 --- /dev/null +++ b/pkg/osbuild/mkswap_stage_test.go @@ -0,0 +1,37 @@ +package osbuild + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" +) + +var expectedJSON = `{ + "type": "org.osbuild.mkswap", + "options": { + "uuid": "8a1fc521-02a0-4917-92a9-90a44d7e6503", + "label": "some-label" + }, + "devices": { + "root": { + "type": "org.osbuild.loopback" + } + } +}` + +func TestNewMkswapStage(t *testing.T) { + devices := make(map[string]Device) + devices["root"] = Device{ + Type: "org.osbuild.loopback", + } + + options := MkswapStageOptions{ + UUID: "8a1fc521-02a0-4917-92a9-90a44d7e6503", + Label: "some-label", + } + stage := NewMkswapStage(&options, devices) + b, err := json.MarshalIndent(stage, "", " ") + assert.NoError(t, err) + assert.Equal(t, expectedJSON, string(b)) +}