get without content
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTreeCrud(t *testing.T) {
|
||||
tree := NewTree(t.TempDir())
|
||||
@@ -27,4 +32,73 @@ func TestTreeCrud(t *testing.T) {
|
||||
} else if l != want {
|
||||
t.Fatal(want, l)
|
||||
}
|
||||
|
||||
if withContent, err := tree.GetRoot(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if withoutContent, err := tree.GetRootMeta(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if fmt.Sprint(withContent) == fmt.Sprint(withoutContent) {
|
||||
with, _ := json.MarshalIndent(withContent, "", " ")
|
||||
without, _ := json.MarshalIndent(withoutContent, "", " ")
|
||||
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