Add tests for disk data and ignition json

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2023-08-22 14:24:16 -06:00
parent d060c3d447
commit 9058682b18
2 changed files with 104 additions and 1 deletions

View File

@@ -37,4 +37,45 @@ nodes:
},
)
assert.NoError(t, err)
}
}
func TestNodeDisk(t *testing.T) {
node_config := `WW_INTERNAL: 43
nodes:
n1:
disks:
/dev/vda:
wipe_table: "true"
partitions:
scratch:
should_exist: "true"
filesystems:
/dev/disk/by-partlabel/scratch:
format: btrfs
path: /scratch
wipe_filesystem: "true"`
config, parse_error := Parse([]byte(node_config))
assert.Empty(t, parse_error)
nodeInfos, info_error := config.FindAllNodes()
assert.Empty(t, info_error)
assert.Len(t, nodeInfos, 1)
node := nodeInfos[0]
assert.Len(t, node.Disks, 1)
assert.Len(t, node.FileSystems, 1)
disk := node.Disks["/dev/vda"]
assert.True(t, disk.WipeTable.GetB())
assert.Len(t, disk.Partitions, 1)
partition := disk.Partitions["scratch"]
assert.True(t, partition.ShouldExist.GetB())
filesystem := node.FileSystems["/dev/disk/by-partlabel/scratch"]
assert.Equal(t, "btrfs", filesystem.Format.Get())
assert.Equal(t, "/scratch", filesystem.Path.Get())
assert.True(t, filesystem.WipeFileSystem.GetB())
}

View File

@@ -0,0 +1,62 @@
package overlay
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/hpcng/warewulf/internal/pkg/node"
)
func Test_createIgnitionJson(t *testing.T) {
node_config := `WW_INTERNAL: 43
nodes:
n1:
disks:
/dev/vda:
wipe_table: "true"
partitions:
scratch:
should_exist: "true"
filesystems:
/dev/disk/by-partlabel/scratch:
format: btrfs
path: /scratch
wipe_filesystem: "true"`
expected_json := `{
"ignition": {
"version": "3.1.0"
},
"storage": {
"disks": [
{
"device": "/dev/vda",
"partitions": [
{
"label": "scratch",
"shouldExist": true,
"wipePartitionEntry": false
}
],
"wipeTable": true
}
],
"filesystems": [
{
"device": "/dev/disk/by-partlabel/scratch",
"format": "btrfs",
"path": "/scratch",
"wipeFilesystem": true
}
]
}
}`
config, parse_error := node.Parse([]byte(node_config))
assert.Empty(t, parse_error)
nodeInfos, info_error := config.FindAllNodes()
assert.Empty(t, info_error)
node := nodeInfos[0]
assert.JSONEq(t, expected_json, createIgnitionJson(&node))
}