Merge second: Copy trees (#3)
This commit is contained in:
parent
18bb252d10
commit
0d2b6551b3
5
tree.go
5
tree.go
@ -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
|
||||
}
|
||||
|
||||
|
35
tree_test.go
35
tree_test.go
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user