Merge second: Copy trees ()

This commit is contained in:
William Murphy 2018-05-31 17:00:40 -04:00 committed by Alex Goodman
parent 18bb252d10
commit 0d2b6551b3
2 changed files with 36 additions and 4 deletions

@ -18,6 +18,7 @@ const (
collapsedItem = "⊕ "
)
type FileTree struct {
root *Node
size int
@ -51,7 +52,9 @@ func NewNode(parent *Node, name string, data *FileChangeInfo) (node *Node) {
node.data = data
node.children = make(map[string]*Node)
node.parent = parent
node.tree = parent.tree
if parent != nil {
node.tree = parent.tree
}
return node
}

@ -105,7 +105,6 @@ func TestPrintTree(t *testing.T) {
}
func TestAddPath(t *testing.T) {
tree := NewTree()
tree.AddPath("/etc/nginx/nginx.conf", nil)
@ -189,7 +188,6 @@ func TestIsWhiteout(t *testing.T) {
}
}
func TestStack(t *testing.T) {
payloadKey := "/var/run/systemd"
payloadValue := FileChangeInfo{
@ -244,4 +242,35 @@ func TestStack(t *testing.T) {
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
}
}
}
func TestCopy(t *testing.T) {
tree := NewTree()
tree.AddPath("/etc/nginx/nginx.conf", nil)
tree.AddPath("/etc/nginx/public", nil)
tree.AddPath("/var/run/systemd", nil)
tree.AddPath("/var/run/bashful", nil)
tree.AddPath("/tmp", nil)
tree.AddPath("/tmp/nonsense", nil)
tree.RemovePath("/var/run/bashful")
tree.RemovePath("/tmp")
expected := `.
etc
nginx
nginx.conf
public
var
run
systemd
`
newTree := tree.Copy()
actual := newTree.String()
if expected != actual {
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
}
}