merge
This commit is contained in:
@@ -3,22 +3,21 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTreeDel(t *testing.T) {
|
||||
tree := NewTree(t.TempDir())
|
||||
if err := tree.Put([]string{"id"}, Leaf{}); err != nil {
|
||||
if err := tree.Put(ID("id"), Leaf{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := tree.Put([]string{"id", "subid"}, Leaf{}); err != nil {
|
||||
if err := tree.Put(ID("id/subid"), Leaf{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := tree.Del([]string{"id"}); err != nil {
|
||||
if err := tree.Del(ID("id")); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if got, err := tree.Get([]string{"id"}); err != nil {
|
||||
} else if got, err := tree.Get(ID("id")); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !got.Deleted {
|
||||
t.Fatal(got)
|
||||
@@ -30,7 +29,7 @@ func TestTreeDel(t *testing.T) {
|
||||
t.Fatal(root.Branches)
|
||||
}
|
||||
|
||||
if root, err := tree.getRoot(false, true); err != nil {
|
||||
if root, err := tree.getRoot(NewID(""), false, true); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(root.Branches) != 1 {
|
||||
t.Fatal(root.Branches)
|
||||
@@ -46,7 +45,7 @@ func TestTreeCrud(t *testing.T) {
|
||||
t.Fatal(m)
|
||||
}
|
||||
|
||||
if err := tree.Del([]string{"id"}); err != nil {
|
||||
if err := tree.Del(ID("id")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -55,9 +54,9 @@ func TestTreeCrud(t *testing.T) {
|
||||
Deleted: false,
|
||||
Content: "leaf content",
|
||||
}
|
||||
if err := tree.Put([]string{"id"}, want); err != nil {
|
||||
if err := tree.Put(ID("id"), want); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if l, err := tree.Get([]string{"id"}); err != nil {
|
||||
} else if l, err := tree.Get(ID("id")); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if l != want {
|
||||
t.Fatal(want, l)
|
||||
@@ -73,62 +72,3 @@ func TestTreeCrud(t *testing.T) {
|
||||
t.Fatalf("without content == with content: \n\twith=%s\n\twout=%s", with, without)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBranchFind(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
want []string
|
||||
found bool
|
||||
branch Branch
|
||||
}{
|
||||
"empty": {
|
||||
input: "id",
|
||||
want: nil,
|
||||
found: false,
|
||||
branch: Branch{},
|
||||
},
|
||||
"yes top level": {
|
||||
input: "id",
|
||||
want: []string{"id"},
|
||||
found: true,
|
||||
branch: Branch{
|
||||
Branches: map[string]Branch{"id": Branch{}},
|
||||
},
|
||||
},
|
||||
"yes deep level": {
|
||||
input: "subsubid",
|
||||
want: []string{"id", "subid", "subsubid"},
|
||||
found: true,
|
||||
branch: Branch{
|
||||
Branches: map[string]Branch{"id": Branch{
|
||||
Branches: map[string]Branch{"subid": Branch{
|
||||
Branches: map[string]Branch{"subsubid": Branch{}}}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
"no but has deep levels": {
|
||||
input: "notsubsubid",
|
||||
want: nil,
|
||||
found: false,
|
||||
branch: Branch{
|
||||
Branches: map[string]Branch{"id": Branch{
|
||||
Branches: map[string]Branch{"subid": Branch{
|
||||
Branches: map[string]Branch{"subsubid": Branch{}}}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got, found := c.branch.Find(c.input)
|
||||
if found != c.found {
|
||||
t.Error(c.found, found)
|
||||
}
|
||||
if path.Join(got...) != path.Join(c.want...) {
|
||||
t.Error(c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user