Added test TestSnapshot_EnsureParents
No using asserts NotNil and Nil
This commit is contained in:
parent
6fd0b3e83e
commit
b873876670
|
@ -17,11 +17,11 @@ SnapshotName-1-1-1="Snapshot 3"
|
|||
SnapshotUUID-1-1-1="eb342b39-b4bd-47b0-afd8-dcd1cc5c5929"
|
||||
SnapshotName-1-1-2="Snapshot 4"
|
||||
SnapshotUUID-1-1-2="17df1668-e79a-4ed6-a86b-713913699846"
|
||||
SnapshotName-1-1-3="Snapshot-Export"
|
||||
SnapshotUUID-1-1-3="c857d1b8-4fd6-4044-9d2c-c6e465b3cdd4"
|
||||
SnapshotName-1-2="Snapshot-Export"
|
||||
SnapshotUUID-1-2="c857d1b8-4fd6-4044-9d2c-c6e465b3cdd4"
|
||||
CurrentSnapshotName="Snapshot-Export"
|
||||
CurrentSnapshotUUID="c857d1b8-4fd6-4044-9d2c-c6e465b3cdd4"
|
||||
CurrentSnapshotNode="SnapshotName-1-1-3"
|
||||
CurrentSnapshotNode="SnapshotName-1-2"
|
||||
SnapshotName-2="Snapshot 5"
|
||||
SnapshotUUID-2="85646c6a-fb86-4112-b15e-cab090670778"
|
||||
SnapshotName-2-1="Snapshot 2"
|
||||
|
@ -37,40 +37,41 @@ SnapshotUUID-3-2="a5903505-9261-4bd3-9972-bacd0064d667"`
|
|||
func TestSnapshot_ParseFullTree(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, rootNode, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, rootNode)
|
||||
assert.Equal(t, rootNode.Name, "Imported")
|
||||
assert.Equal(t, rootNode.UUID, "7e5b4165-91ec-4091-a74c-a5709d584530")
|
||||
assert.Equal(t, len(rootNode.Children), 3)
|
||||
assert.Equal(t, (*VBoxSnapshot)(nil), rootNode.Parent)
|
||||
assert.Equal(t, 3, len(rootNode.Children))
|
||||
assert.Nil(t, rootNode.Parent)
|
||||
}
|
||||
|
||||
func TestSnapshot_FindCurrent(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, rootNode, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
current := rootNode.GetCurrentSnapshot()
|
||||
assert.NotEqual(t, current, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, current)
|
||||
assert.Equal(t, current.UUID, "c857d1b8-4fd6-4044-9d2c-c6e465b3cdd4")
|
||||
assert.Equal(t, current.Name, "Snapshot-Export")
|
||||
assert.NotEqual(t, current.Parent, (*VBoxSnapshot)(nil))
|
||||
assert.Equal(t, current.Parent.UUID, "8e12833b-c6b5-4cbd-b42b-09eff8ffc173")
|
||||
assert.Equal(t, current.Parent.Name, "Snapshot 2")
|
||||
assert.NotNil(t, current.Parent)
|
||||
assert.Equal(t, current.Parent.UUID, "5fc461ec-da7a-40a8-a168-03134d7cdf5c")
|
||||
assert.Equal(t, current.Parent.Name, "Snapshot 1")
|
||||
}
|
||||
|
||||
func TestSnapshot_FindNodeByUUID(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, rootNode, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
node := rootNode.GetSnapshotByUUID("7b093686-2981-4ada-8b0f-4c03ae23cd1a")
|
||||
assert.NotEqual(t, node, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, node)
|
||||
assert.Equal(t, "Snapshot 2", node.Name)
|
||||
assert.Equal(t, "7b093686-2981-4ada-8b0f-4c03ae23cd1a", node.UUID)
|
||||
assert.Equal(t, 0, len(node.Children))
|
||||
assert.Equal(t, rootNode.Parent, (*VBoxSnapshot)(nil))
|
||||
assert.Nil(t, rootNode.Parent)
|
||||
|
||||
otherNode := rootNode.GetSnapshotByUUID("f4ed75b3-afc1-42d4-9e02-8df6f053d07e")
|
||||
assert.NotEqual(t, otherNode, (*VBoxSnapshot)(nil))
|
||||
assert.NotNil(t, otherNode)
|
||||
assert.True(t, otherNode.IsChildOf(rootNode))
|
||||
assert.False(t, node.IsChildOf(otherNode))
|
||||
assert.False(t, otherNode.IsChildOf(node))
|
||||
|
@ -79,20 +80,20 @@ func TestSnapshot_FindNodeByUUID(t *testing.T) {
|
|||
func TestSnapshot_FindNodesByName(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, nil, rootNode)
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
nodes := rootNode.GetSnapshotsByName("Snapshot 2")
|
||||
assert.NotEqual(t, nil, nodes)
|
||||
assert.NotNil(t, nodes)
|
||||
assert.Equal(t, 2, len(nodes))
|
||||
}
|
||||
|
||||
func TestSnapshot_IsChildOf(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, nil, rootNode)
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
child := rootNode.GetSnapshotByUUID("c857d1b8-4fd6-4044-9d2c-c6e465b3cdd4")
|
||||
assert.NotEqual(t, (*VBoxSnapshot)(nil), child)
|
||||
assert.NotNil(t, child)
|
||||
assert.True(t, child.IsChildOf(rootNode))
|
||||
assert.True(t, child.IsChildOf(child.Parent))
|
||||
assert.PanicsWithValue(t, "Missing parameter value: candidate", func() { child.IsChildOf(nil) })
|
||||
|
@ -104,12 +105,12 @@ func TestSnapshot_SingleSnapshot(t *testing.T) {
|
|||
|
||||
rootNode, err := ParseSnapshotData(snapData)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, (*VBoxSnapshot)(nil), rootNode)
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
assert.Equal(t, rootNode.Name, "Imported")
|
||||
assert.Equal(t, rootNode.UUID, "7e5b4165-91ec-4091-a74c-a5709d584530")
|
||||
assert.Equal(t, len(rootNode.Children), 0)
|
||||
assert.Equal(t, (*VBoxSnapshot)(nil), rootNode.Parent)
|
||||
assert.Nil(t, rootNode.Parent)
|
||||
}
|
||||
|
||||
func TestSnapshot_EmptySnapshotData(t *testing.T) {
|
||||
|
@ -117,5 +118,19 @@ func TestSnapshot_EmptySnapshotData(t *testing.T) {
|
|||
|
||||
rootNode, err := ParseSnapshotData(snapData)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, (*VBoxSnapshot)(nil), rootNode)
|
||||
assert.Nil(t, rootNode)
|
||||
}
|
||||
|
||||
func TestSnapshot_EnsureParents(t *testing.T) {
|
||||
rootNode, err := ParseSnapshotData(getTestData())
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, rootNode)
|
||||
|
||||
for _, snapshot := range rootNode.GetSnapshots() {
|
||||
if snapshot == rootNode {
|
||||
assert.Nil(t, snapshot.Parent)
|
||||
} else {
|
||||
assert.NotNil(t, snapshot.Parent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue