diff --git a/internal/pkg/node/node_test.go b/internal/pkg/node/node_test.go index 988b4144..13003a06 100644 --- a/internal/pkg/node/node_test.go +++ b/internal/pkg/node/node_test.go @@ -37,4 +37,45 @@ nodes: }, ) assert.NoError(t, err) -} \ No newline at end of file +} + + +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()) +} diff --git a/internal/pkg/overlay/funcmap_test.go b/internal/pkg/overlay/funcmap_test.go new file mode 100644 index 00000000..ab1a4be2 --- /dev/null +++ b/internal/pkg/overlay/funcmap_test.go @@ -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)) +}