Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
func TestBuildPathTreeExcludesUserNamespace(t *testing.T) {
|
|
database, err := sql.Open("sqlite", "file:tree-user-namespace-test?mode=memory&cache=shared")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = database.Close() })
|
|
if _, err := database.Exec(`CREATE TABLE paths(domain_uuid TEXT,path TEXT); INSERT INTO paths VALUES('d','/u'),('d','/u/alice'),('d','/u/alice/note'),('d','/docs/guide')`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st := &Store{DB: database}
|
|
tree, err := st.BuildPathTreeInDomain("d")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var flattened []FlatTreeNode
|
|
FlattenTree(tree, 0, &flattened)
|
|
for _, node := range flattened {
|
|
if node.FullPath == "/u" || len(node.FullPath) > 3 && node.FullPath[:3] == "/u/" {
|
|
t.Fatalf("user namespace leaked into Tree View: %q", node.FullPath)
|
|
}
|
|
}
|
|
if len(flattened) != 2 || flattened[0].FullPath != "/docs" || flattened[1].FullPath != "/docs/guide" {
|
|
t.Fatalf("tree = %#v", flattened)
|
|
}
|
|
}
|
|
|
|
func TestTreeScopeUsesLiteralPathAndDomain(t *testing.T) {
|
|
database, err := sql.Open("sqlite", ":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = database.Close() })
|
|
if _, err := database.Exec(`CREATE TABLE paths(domain_uuid TEXT,path TEXT);
|
|
INSERT INTO paths VALUES('d','/docs/a/b'),('d','/docs/a/c'),('d','/docset/hidden'),
|
|
('other','/docs/secret'),('d','/a_%/child'),('d','/a12/hidden'),('d','/Docs/hidden'),('d','/u/alice');`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st := &Store{DB: database}
|
|
for _, tc := range []struct {
|
|
root string
|
|
want []string
|
|
}{
|
|
{"/docs", []string{"/docs", "/docs/a", "/docs/a/b", "/docs/a/c"}},
|
|
{"/a_%", []string{"/a_%", "/a_%/child"}},
|
|
{"/missing", []string{"/missing"}},
|
|
} {
|
|
tree, err := st.BuildPathTreeAtInDomain("d", tc.root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var nodes []FlatTreeNode
|
|
FlattenTree(tree, 0, &nodes)
|
|
if len(nodes) != len(tc.want) {
|
|
t.Fatalf("%s: %#v", tc.root, nodes)
|
|
}
|
|
for i, want := range tc.want {
|
|
if nodes[i].FullPath != want {
|
|
t.Fatalf("%s: %#v", tc.root, nodes)
|
|
}
|
|
}
|
|
if len(nodes) > 1 && nodes[1].Depth != 1 {
|
|
t.Fatalf("relative depth: %#v", nodes)
|
|
}
|
|
}
|
|
}
|