Add tests for disk data and ignition json
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
62
internal/pkg/overlay/funcmap_test.go
Normal file
62
internal/pkg/overlay/funcmap_test.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user