remove root node from view; fix tests
This commit is contained in:
parent
3590a7cf46
commit
c9b1d3dd3c
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
func TestAssignDiffType(t *testing.T) {
|
func TestAssignDiffType(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
node, err := tree.AddPath("/usr", BlankFileChangeInfo("/usr"))
|
node, err := tree.AddPath("/usr", *BlankFileChangeInfo("/usr"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error from fetching path. got: %v", err)
|
t.Errorf("Expected no error from fetching path. got: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AttributeFormat = "%s%s %10s %10s "
|
AttributeFormat = "%7s%1s %10s %10s "
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileNode struct {
|
type FileNode struct {
|
||||||
|
@ -12,14 +12,14 @@ func TestAddChild(t *testing.T) {
|
|||||||
Path: "stufffffs",
|
Path: "stufffffs",
|
||||||
}
|
}
|
||||||
|
|
||||||
one := tree.Root.AddChild("first node!", &payload)
|
one := tree.Root.AddChild("first node!", payload)
|
||||||
|
|
||||||
two := tree.Root.AddChild("nil node!", nil)
|
two := tree.Root.AddChild("nil node!", FileInfo{})
|
||||||
|
|
||||||
tree.Root.AddChild("third node!", nil)
|
tree.Root.AddChild("third node!", FileInfo{})
|
||||||
two.AddChild("forth, one level down...", nil)
|
two.AddChild("forth, one level down...", FileInfo{})
|
||||||
two.AddChild("fifth, one level down...", nil)
|
two.AddChild("fifth, one level down...", FileInfo{})
|
||||||
two.AddChild("fifth, one level down...", nil)
|
two.AddChild("fifth, one level down...", FileInfo{})
|
||||||
|
|
||||||
expected, actual = 5, tree.Size
|
expected, actual = 5, tree.Size
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
@ -36,17 +36,14 @@ func TestAddChild(t *testing.T) {
|
|||||||
t.Errorf("Expected 'twos' number of children to be %d got %d.", expected, actual)
|
t.Errorf("Expected 'twos' number of children to be %d got %d.", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedFC := &FileInfo{
|
expectedFC := FileInfo{
|
||||||
Path: "stufffffs",
|
Path: "stufffffs",
|
||||||
}
|
}
|
||||||
actualFC := one.Data.FileInfo
|
actualFC := one.Data.FileInfo
|
||||||
if *expectedFC != *actualFC {
|
if expectedFC.Path != actualFC.Path {
|
||||||
t.Errorf("Expected 'ones' payload to be %+v got %+v.", expectedFC, actualFC)
|
t.Errorf("Expected 'ones' payload to be %+v got %+v.", expectedFC, actualFC)
|
||||||
}
|
}
|
||||||
|
|
||||||
if two.Data.FileInfo != nil {
|
|
||||||
t.Errorf("Expected 'twos' payload to be nil got %+v.", two.Data.FileInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,11 +51,11 @@ func TestRemoveChild(t *testing.T) {
|
|||||||
var expected, actual int
|
var expected, actual int
|
||||||
|
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.Root.AddChild("first", nil)
|
tree.Root.AddChild("first", FileInfo{})
|
||||||
two := tree.Root.AddChild("nil", nil)
|
two := tree.Root.AddChild("nil", FileInfo{})
|
||||||
tree.Root.AddChild("third", nil)
|
tree.Root.AddChild("third", FileInfo{})
|
||||||
forth := two.AddChild("forth", nil)
|
forth := two.AddChild("forth", FileInfo{})
|
||||||
two.AddChild("fifth", nil)
|
two.AddChild("fifth", FileInfo{})
|
||||||
|
|
||||||
forth.Remove()
|
forth.Remove()
|
||||||
|
|
||||||
@ -87,7 +84,7 @@ func TestRemoveChild(t *testing.T) {
|
|||||||
func TestPath(t *testing.T) {
|
func TestPath(t *testing.T) {
|
||||||
expected := "/etc/nginx/nginx.conf"
|
expected := "/etc/nginx/nginx.conf"
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
node, _ := tree.AddPath(expected, nil)
|
node, _ := tree.AddPath(expected, FileInfo{})
|
||||||
|
|
||||||
actual := node.Path()
|
actual := node.Path()
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
@ -97,8 +94,8 @@ func TestPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsWhiteout(t *testing.T) {
|
func TestIsWhiteout(t *testing.T) {
|
||||||
tree1 := NewFileTree()
|
tree1 := NewFileTree()
|
||||||
p1, _ := tree1.AddPath("/etc/nginx/public1", nil)
|
p1, _ := tree1.AddPath("/etc/nginx/public1", FileInfo{})
|
||||||
p2, _ := tree1.AddPath("/etc/nginx/.wh.public2", nil)
|
p2, _ := tree1.AddPath("/etc/nginx/.wh.public2", FileInfo{})
|
||||||
|
|
||||||
if p1.IsWhiteout() != false {
|
if p1.IsWhiteout() != false {
|
||||||
t.Errorf("Expected Path '%s' to **not** be a whiteout file", p1.Name)
|
t.Errorf("Expected Path '%s' to **not** be a whiteout file", p1.Name)
|
||||||
@ -111,15 +108,15 @@ func TestIsWhiteout(t *testing.T) {
|
|||||||
|
|
||||||
func TestDiffTypeFromAddedChildren(t *testing.T) {
|
func TestDiffTypeFromAddedChildren(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
node, _ := tree.AddPath("/usr", BlankFileChangeInfo("/usr"))
|
node, _ := tree.AddPath("/usr", *BlankFileChangeInfo("/usr"))
|
||||||
node.Data.DiffType = Unchanged
|
node.Data.DiffType = Unchanged
|
||||||
|
|
||||||
info1 := BlankFileChangeInfo("/usr/bin")
|
info1 := BlankFileChangeInfo("/usr/bin")
|
||||||
node, _ = tree.AddPath("/usr/bin", info1)
|
node, _ = tree.AddPath("/usr/bin", *info1)
|
||||||
node.Data.DiffType = Added
|
node.Data.DiffType = Added
|
||||||
|
|
||||||
info2 := BlankFileChangeInfo("/usr/bin2")
|
info2 := BlankFileChangeInfo("/usr/bin2")
|
||||||
node, _ = tree.AddPath("/usr/bin2", info2)
|
node, _ = tree.AddPath("/usr/bin2", *info2)
|
||||||
node.Data.DiffType = Removed
|
node.Data.DiffType = Removed
|
||||||
|
|
||||||
tree.Root.Children["usr"].deriveDiffType(Unchanged)
|
tree.Root.Children["usr"].deriveDiffType(Unchanged)
|
||||||
@ -130,14 +127,14 @@ func TestDiffTypeFromAddedChildren(t *testing.T) {
|
|||||||
}
|
}
|
||||||
func TestDiffTypeFromRemovedChildren(t *testing.T) {
|
func TestDiffTypeFromRemovedChildren(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
node, _ := tree.AddPath("/usr", BlankFileChangeInfo("/usr"))
|
node, _ := tree.AddPath("/usr", *BlankFileChangeInfo("/usr"))
|
||||||
|
|
||||||
info1 := BlankFileChangeInfo("/usr/.wh.bin")
|
info1 := BlankFileChangeInfo("/usr/.wh.bin")
|
||||||
node, _ = tree.AddPath("/usr/.wh.bin", info1)
|
node, _ = tree.AddPath("/usr/.wh.bin", *info1)
|
||||||
node.Data.DiffType = Removed
|
node.Data.DiffType = Removed
|
||||||
|
|
||||||
info2 := BlankFileChangeInfo("/usr/.wh.bin2")
|
info2 := BlankFileChangeInfo("/usr/.wh.bin2")
|
||||||
node, _ = tree.AddPath("/usr/.wh.bin2", info2)
|
node, _ = tree.AddPath("/usr/.wh.bin2", *info2)
|
||||||
node.Data.DiffType = Removed
|
node.Data.DiffType = Removed
|
||||||
|
|
||||||
tree.Root.Children["usr"].deriveDiffType(Unchanged)
|
tree.Root.Children["usr"].deriveDiffType(Unchanged)
|
||||||
|
@ -32,7 +32,7 @@ func NewFileTree() (tree *FileTree) {
|
|||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tree *FileTree) String() string {
|
func (tree *FileTree) String(showAttributes bool) string {
|
||||||
var renderTreeLine func(string, []bool, bool, bool) string
|
var renderTreeLine func(string, []bool, bool, bool) string
|
||||||
var walkTree func(*FileNode, []bool, int) string
|
var walkTree func(*FileNode, []bool, int) string
|
||||||
|
|
||||||
@ -73,7 +73,10 @@ func (tree *FileTree) String() string {
|
|||||||
}
|
}
|
||||||
last := idx == (len(node.Children) - 1)
|
last := idx == (len(node.Children) - 1)
|
||||||
showCollapsed := child.Data.ViewInfo.Collapsed && len(child.Children) > 0
|
showCollapsed := child.Data.ViewInfo.Collapsed && len(child.Children) > 0
|
||||||
result += child.MetadataString() + " " + renderTreeLine(child.String(), spaces, last, showCollapsed)
|
if showAttributes {
|
||||||
|
result += child.MetadataString() + " "
|
||||||
|
}
|
||||||
|
result += renderTreeLine(child.String(), spaces, last, showCollapsed)
|
||||||
if len(child.Children) > 0 && !child.Data.ViewInfo.Collapsed {
|
if len(child.Children) > 0 && !child.Data.ViewInfo.Collapsed {
|
||||||
spacesChild := append(spaces, last)
|
spacesChild := append(spaces, last)
|
||||||
result += walkTree(child, spacesChild, depth+1)
|
result += walkTree(child, spacesChild, depth+1)
|
||||||
@ -82,7 +85,7 @@ func (tree *FileTree) String() string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
return "." + newLine + walkTree(tree.Root, []bool{}, 0)
|
return walkTree(tree.Root, []bool{}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tree *FileTree) Copy() *FileTree {
|
func (tree *FileTree) Copy() *FileTree {
|
||||||
|
@ -15,9 +15,6 @@ func stringInSlice(a string, list []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertDiffType(node *FileNode, expectedDiffType DiffType) error {
|
func AssertDiffType(node *FileNode, expectedDiffType DiffType) error {
|
||||||
if node.Data.FileInfo == nil {
|
|
||||||
return fmt.Errorf("expected *FileInfo but got nil at Path %s", node.Path())
|
|
||||||
}
|
|
||||||
if node.Data.DiffType != expectedDiffType {
|
if node.Data.DiffType != expectedDiffType {
|
||||||
return fmt.Errorf("Expecting node at %s to have DiffType %v, but had %v", node.Path(), expectedDiffType, node.Data.DiffType)
|
return fmt.Errorf("Expecting node at %s to have DiffType %v, but had %v", node.Path(), expectedDiffType, node.Data.DiffType)
|
||||||
}
|
}
|
||||||
@ -26,18 +23,18 @@ func AssertDiffType(node *FileNode, expectedDiffType DiffType) error {
|
|||||||
|
|
||||||
func TestPrintTree(t *testing.T) {
|
func TestPrintTree(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.Root.AddChild("first node!", nil)
|
tree.Root.AddChild("first node!", FileInfo{})
|
||||||
two := tree.Root.AddChild("second node!", nil)
|
two := tree.Root.AddChild("second node!", FileInfo{})
|
||||||
tree.Root.AddChild("third node!", nil)
|
tree.Root.AddChild("third node!", FileInfo{})
|
||||||
two.AddChild("forth, one level down...", nil)
|
two.AddChild("forth, one level down...", FileInfo{})
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
├── first node!
|
`├── first node!
|
||||||
├── second node!
|
├── second node!
|
||||||
│ └── forth, one level down...
|
│ └── forth, one level down...
|
||||||
└── third node!
|
└── third node!
|
||||||
`
|
`
|
||||||
actual := tree.String()
|
actual := tree.String(false)
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
@ -47,15 +44,15 @@ func TestPrintTree(t *testing.T) {
|
|||||||
|
|
||||||
func TestAddPath(t *testing.T) {
|
func TestAddPath(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.AddPath("/etc/nginx/nginx.conf", nil)
|
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||||
tree.AddPath("/etc/nginx/public", nil)
|
tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||||
tree.AddPath("/var/run/systemd", nil)
|
tree.AddPath("/var/run/systemd", FileInfo{})
|
||||||
tree.AddPath("/var/run/bashful", nil)
|
tree.AddPath("/var/run/bashful", FileInfo{})
|
||||||
tree.AddPath("/tmp", nil)
|
tree.AddPath("/tmp", FileInfo{})
|
||||||
tree.AddPath("/tmp/nonsense", nil)
|
tree.AddPath("/tmp/nonsense", FileInfo{})
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
├── etc
|
`├── etc
|
||||||
│ └── nginx
|
│ └── nginx
|
||||||
│ ├── nginx.conf
|
│ ├── nginx.conf
|
||||||
│ └── public
|
│ └── public
|
||||||
@ -66,7 +63,7 @@ func TestAddPath(t *testing.T) {
|
|||||||
├── bashful
|
├── bashful
|
||||||
└── systemd
|
└── systemd
|
||||||
`
|
`
|
||||||
actual := tree.String()
|
actual := tree.String(false)
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
@ -76,18 +73,18 @@ func TestAddPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemovePath(t *testing.T) {
|
func TestRemovePath(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.AddPath("/etc/nginx/nginx.conf", nil)
|
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||||
tree.AddPath("/etc/nginx/public", nil)
|
tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||||
tree.AddPath("/var/run/systemd", nil)
|
tree.AddPath("/var/run/systemd", FileInfo{})
|
||||||
tree.AddPath("/var/run/bashful", nil)
|
tree.AddPath("/var/run/bashful", FileInfo{})
|
||||||
tree.AddPath("/tmp", nil)
|
tree.AddPath("/tmp", FileInfo{})
|
||||||
tree.AddPath("/tmp/nonsense", nil)
|
tree.AddPath("/tmp/nonsense", FileInfo{})
|
||||||
|
|
||||||
tree.RemovePath("/var/run/bashful")
|
tree.RemovePath("/var/run/bashful")
|
||||||
tree.RemovePath("/tmp")
|
tree.RemovePath("/tmp")
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
├── etc
|
`├── etc
|
||||||
│ └── nginx
|
│ └── nginx
|
||||||
│ ├── nginx.conf
|
│ ├── nginx.conf
|
||||||
│ └── public
|
│ └── public
|
||||||
@ -95,7 +92,7 @@ func TestRemovePath(t *testing.T) {
|
|||||||
└── run
|
└── run
|
||||||
└── systemd
|
└── systemd
|
||||||
`
|
`
|
||||||
actual := tree.String()
|
actual := tree.String(false)
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
@ -111,20 +108,20 @@ func TestStack(t *testing.T) {
|
|||||||
|
|
||||||
tree1 := NewFileTree()
|
tree1 := NewFileTree()
|
||||||
|
|
||||||
tree1.AddPath("/etc/nginx/public", nil)
|
tree1.AddPath("/etc/nginx/public", FileInfo{})
|
||||||
tree1.AddPath(payloadKey, nil)
|
tree1.AddPath(payloadKey, FileInfo{})
|
||||||
tree1.AddPath("/var/run/bashful", nil)
|
tree1.AddPath("/var/run/bashful", FileInfo{})
|
||||||
tree1.AddPath("/tmp", nil)
|
tree1.AddPath("/tmp", FileInfo{})
|
||||||
tree1.AddPath("/tmp/nonsense", nil)
|
tree1.AddPath("/tmp/nonsense", FileInfo{})
|
||||||
|
|
||||||
tree2 := NewFileTree()
|
tree2 := NewFileTree()
|
||||||
// add new files
|
// add new files
|
||||||
tree2.AddPath("/etc/nginx/nginx.conf", nil)
|
tree2.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||||
// modify current files
|
// modify current files
|
||||||
tree2.AddPath(payloadKey, &payloadValue)
|
tree2.AddPath(payloadKey, payloadValue)
|
||||||
// whiteout the following files
|
// whiteout the following files
|
||||||
tree2.AddPath("/var/run/.wh.bashful", nil)
|
tree2.AddPath("/var/run/.wh.bashful", FileInfo{})
|
||||||
tree2.AddPath("/.wh.tmp", nil)
|
tree2.AddPath("/.wh.tmp", FileInfo{})
|
||||||
|
|
||||||
err := tree1.Stack(tree2)
|
err := tree1.Stack(tree2)
|
||||||
|
|
||||||
@ -132,8 +129,8 @@ func TestStack(t *testing.T) {
|
|||||||
t.Errorf("Could not stack refTrees: %v", err)
|
t.Errorf("Could not stack refTrees: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
├── etc
|
`├── etc
|
||||||
│ └── nginx
|
│ └── nginx
|
||||||
│ ├── nginx.conf
|
│ ├── nginx.conf
|
||||||
│ └── public
|
│ └── public
|
||||||
@ -147,11 +144,11 @@ func TestStack(t *testing.T) {
|
|||||||
t.Errorf("Expected '%s' to still exist, but it doesn't", payloadKey)
|
t.Errorf("Expected '%s' to still exist, but it doesn't", payloadKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *node.Data.FileInfo != payloadValue {
|
if node.Data.FileInfo.Path != payloadValue.Path {
|
||||||
t.Errorf("Expected '%s' value to be %+v but got %+v", payloadKey, payloadValue, node.Data.FileInfo)
|
t.Errorf("Expected '%s' value to be %+v but got %+v", payloadKey, payloadValue, node.Data.FileInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := tree1.String()
|
actual := tree1.String(false)
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
@ -161,18 +158,18 @@ func TestStack(t *testing.T) {
|
|||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.AddPath("/etc/nginx/nginx.conf", nil)
|
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||||
tree.AddPath("/etc/nginx/public", nil)
|
tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||||
tree.AddPath("/var/run/systemd", nil)
|
tree.AddPath("/var/run/systemd", FileInfo{})
|
||||||
tree.AddPath("/var/run/bashful", nil)
|
tree.AddPath("/var/run/bashful", FileInfo{})
|
||||||
tree.AddPath("/tmp", nil)
|
tree.AddPath("/tmp", FileInfo{})
|
||||||
tree.AddPath("/tmp/nonsense", nil)
|
tree.AddPath("/tmp/nonsense", FileInfo{})
|
||||||
|
|
||||||
tree.RemovePath("/var/run/bashful")
|
tree.RemovePath("/var/run/bashful")
|
||||||
tree.RemovePath("/tmp")
|
tree.RemovePath("/tmp")
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
├── etc
|
`├── etc
|
||||||
│ └── nginx
|
│ └── nginx
|
||||||
│ ├── nginx.conf
|
│ ├── nginx.conf
|
||||||
│ └── public
|
│ └── public
|
||||||
@ -182,7 +179,7 @@ func TestCopy(t *testing.T) {
|
|||||||
`
|
`
|
||||||
|
|
||||||
NewFileTree := tree.Copy()
|
NewFileTree := tree.Copy()
|
||||||
actual := NewFileTree.String()
|
actual := NewFileTree.String(false)
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
@ -201,18 +198,14 @@ func TestCompareWithNoChanges(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
lowerTree.AddPath(value, &fakeData)
|
lowerTree.AddPath(value, fakeData)
|
||||||
upperTree.AddPath(value, &fakeData)
|
upperTree.AddPath(value, fakeData)
|
||||||
}
|
}
|
||||||
lowerTree.Compare(upperTree)
|
lowerTree.Compare(upperTree)
|
||||||
asserter := func(n *FileNode) error {
|
asserter := func(n *FileNode) error {
|
||||||
if n.Path() == "/" {
|
if n.Path() == "/" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if n.Data.FileInfo == nil {
|
|
||||||
t.Errorf("Expected *FileInfo but got nil")
|
|
||||||
return fmt.Errorf("expected *FileInfo but got nil")
|
|
||||||
}
|
|
||||||
if (n.Data.DiffType) != Unchanged {
|
if (n.Data.DiffType) != Unchanged {
|
||||||
t.Errorf("Expecting node at %s to have DiffType unchanged, but had %v", n.Path(), n.Data.DiffType)
|
t.Errorf("Expecting node at %s to have DiffType unchanged, but had %v", n.Path(), n.Data.DiffType)
|
||||||
}
|
}
|
||||||
@ -231,7 +224,7 @@ func TestCompareWithAdds(t *testing.T) {
|
|||||||
upperPaths := [...]string{"/etc", "/etc/sudoers", "/usr", "/etc/hosts", "/usr/bin", "/usr/bin/bash"}
|
upperPaths := [...]string{"/etc", "/etc/sudoers", "/usr", "/etc/hosts", "/usr/bin", "/usr/bin/bash"}
|
||||||
|
|
||||||
for _, value := range lowerPaths {
|
for _, value := range lowerPaths {
|
||||||
lowerTree.AddPath(value, &FileInfo{
|
lowerTree.AddPath(value, FileInfo{
|
||||||
Path: value,
|
Path: value,
|
||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
@ -239,7 +232,7 @@ func TestCompareWithAdds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range upperPaths {
|
for _, value := range upperPaths {
|
||||||
upperTree.AddPath(value, &FileInfo{
|
upperTree.AddPath(value, FileInfo{
|
||||||
Path: value,
|
Path: value,
|
||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
@ -291,12 +284,12 @@ func TestCompareWithChanges(t *testing.T) {
|
|||||||
paths := [...]string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}
|
paths := [...]string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}
|
||||||
|
|
||||||
for _, value := range paths {
|
for _, value := range paths {
|
||||||
lowerTree.AddPath(value, &FileInfo{
|
lowerTree.AddPath(value, FileInfo{
|
||||||
Path: value,
|
Path: value,
|
||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
})
|
})
|
||||||
upperTree.AddPath(value, &FileInfo{
|
upperTree.AddPath(value, FileInfo{
|
||||||
Path: value,
|
Path: value,
|
||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
|
||||||
@ -348,7 +341,7 @@ func TestCompareWithRemoves(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
lowerTree.AddPath(value, &fakeData)
|
lowerTree.AddPath(value, fakeData)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range upperPaths {
|
for _, value := range upperPaths {
|
||||||
@ -357,7 +350,7 @@ func TestCompareWithRemoves(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
upperTree.AddPath(value, &fakeData)
|
upperTree.AddPath(value, fakeData)
|
||||||
}
|
}
|
||||||
|
|
||||||
lowerTree.Compare(upperTree)
|
lowerTree.Compare(upperTree)
|
||||||
@ -397,12 +390,12 @@ func TestCompareWithRemoves(t *testing.T) {
|
|||||||
|
|
||||||
func TestStackRange(t *testing.T) {
|
func TestStackRange(t *testing.T) {
|
||||||
tree := NewFileTree()
|
tree := NewFileTree()
|
||||||
tree.AddPath("/etc/nginx/nginx.conf", nil)
|
tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||||
tree.AddPath("/etc/nginx/public", nil)
|
tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||||
tree.AddPath("/var/run/systemd", nil)
|
tree.AddPath("/var/run/systemd", FileInfo{})
|
||||||
tree.AddPath("/var/run/bashful", nil)
|
tree.AddPath("/var/run/bashful", FileInfo{})
|
||||||
tree.AddPath("/tmp", nil)
|
tree.AddPath("/tmp", FileInfo{})
|
||||||
tree.AddPath("/tmp/nonsense", nil)
|
tree.AddPath("/tmp/nonsense", FileInfo{})
|
||||||
|
|
||||||
tree.RemovePath("/var/run/bashful")
|
tree.RemovePath("/var/run/bashful")
|
||||||
tree.RemovePath("/tmp")
|
tree.RemovePath("/tmp")
|
||||||
@ -418,7 +411,7 @@ func TestStackRange(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
lowerTree.AddPath(value, &fakeData)
|
lowerTree.AddPath(value, fakeData)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range upperPaths {
|
for _, value := range upperPaths {
|
||||||
@ -427,7 +420,7 @@ func TestStackRange(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
upperTree.AddPath(value, &fakeData)
|
upperTree.AddPath(value, fakeData)
|
||||||
}
|
}
|
||||||
trees := []*FileTree{lowerTree, upperTree, tree}
|
trees := []*FileTree{lowerTree, upperTree, tree}
|
||||||
StackRange(trees, 2)
|
StackRange(trees, 2)
|
||||||
@ -445,7 +438,7 @@ func TestRemoveOnIterate(t *testing.T) {
|
|||||||
Typeflag: 1,
|
Typeflag: 1,
|
||||||
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
MD5sum: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
node, err := tree.AddPath(value, &fakeData)
|
node, err := tree.AddPath(value, fakeData)
|
||||||
if err == nil && stringInSlice(node.Path(), []string{"/etc"}) {
|
if err == nil && stringInSlice(node.Path(), []string{"/etc"}) {
|
||||||
node.Data.ViewInfo.Hidden = true
|
node.Data.ViewInfo.Hidden = true
|
||||||
}
|
}
|
||||||
@ -458,12 +451,12 @@ func TestRemoveOnIterate(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
expected := `.
|
expected :=
|
||||||
└── usr
|
`└── usr
|
||||||
├── bin
|
├── bin
|
||||||
└── something
|
└── something
|
||||||
`
|
`
|
||||||
actual := tree.String()
|
actual := tree.String(false)
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
t.Errorf("Expected tree string:\n--->%s<---\nGot:\n--->%s<---", expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -136,16 +136,11 @@ func (view *FileTreeView) getAbsPositionNode() (node *filetree.FileNode) {
|
|||||||
var evaluator func(*filetree.FileNode) bool
|
var evaluator func(*filetree.FileNode) bool
|
||||||
var dfsCounter int
|
var dfsCounter int
|
||||||
|
|
||||||
// special case: the root node is never visited
|
|
||||||
if view.TreeIndex == 0 {
|
|
||||||
return view.ModelTree.Root
|
|
||||||
}
|
|
||||||
|
|
||||||
visiter = func(curNode *filetree.FileNode) error {
|
visiter = func(curNode *filetree.FileNode) error {
|
||||||
dfsCounter++
|
|
||||||
if dfsCounter == view.TreeIndex {
|
if dfsCounter == view.TreeIndex {
|
||||||
node = curNode
|
node = curNode
|
||||||
}
|
}
|
||||||
|
dfsCounter++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +200,7 @@ func (view *FileTreeView) KeyHelp() string {
|
|||||||
|
|
||||||
func (view *FileTreeView) Render() error {
|
func (view *FileTreeView) Render() error {
|
||||||
// print the tree to the view
|
// print the tree to the view
|
||||||
lines := strings.Split(view.ViewTree.String(), "\n")
|
lines := strings.Split(view.ViewTree.String(true), "\n")
|
||||||
view.gui.Update(func(g *gocui.Gui) error {
|
view.gui.Update(func(g *gocui.Gui) error {
|
||||||
view.view.Clear()
|
view.view.Clear()
|
||||||
for idx, line := range lines {
|
for idx, line := range lines {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user