notes-server/filetree/path_test.go

78 lines
1.2 KiB
Go
Executable File

package filetree
import (
"gitea.inhome.blapointe.com/local/notes-server/config"
"testing"
)
func TestPathIs(t *testing.T) {
p := Path{Local: "/dev/null"}
if ok := p.IsDir(); ok {
t.Fatal(ok, p)
}
if ok := p.IsFile(); !ok {
t.Fatal(ok, p)
}
p = Path{Local: "/tmp"}
if ok := p.IsDir(); !ok {
t.Fatal(ok, p)
}
if ok := p.IsFile(); ok {
t.Fatal(ok, p)
}
}
func TestNewPathFromLocal(t *testing.T) {
cases := []struct {
in string
root string
href string
local string
}{
{
in: "/wiki/wiki/b/a.md",
root: "/wiki/wiki",
href: "/notes/b/a.md",
local: "/wiki/wiki/b/a.md",
},
{
in: "/wiki/b/a.md",
root: "/wiki",
href: "/notes/b/a.md",
local: "/wiki/b/a.md",
},
{
in: "/wiki/a.md",
root: "/wiki",
href: "/notes/a.md",
local: "/wiki/a.md",
},
{
in: "/b/a.md",
root: "/",
href: "/notes/b/a.md",
local: "/b/a.md",
},
{
in: "/a.md",
root: "/",
href: "/notes/a.md",
local: "/a.md",
},
}
for i, c := range cases {
config.Root = c.root
p := NewPathFromLocal(c.in)
if p.HREF != c.href {
t.Fatal(i, "href", p.HREF, c.href, c, p)
}
if p.Local != c.local {
t.Fatal(i, "local", p.Local, c.local, c, p)
}
}
}