68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package nextcloud
|
|
|
|
import "testing"
|
|
|
|
func TestDecodeDAVPath(t *testing.T) {
|
|
got := decodeDAVPath("/Documents/My%20File.docx")
|
|
want := "/Documents/My File.docx"
|
|
if got != want {
|
|
t.Fatalf("decodeDAVPath() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestClientPathFromDAVHref(t *testing.T) {
|
|
href := "/remote.php/dav/files/user%40example.com/Documents/Hello%20World/"
|
|
got := clientPathFromDAVHref(href)
|
|
want := "/Documents/Hello World"
|
|
if got != want {
|
|
t.Fatalf("clientPathFromDAVHref() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestFileNameFromDAVPropPrefersDisplayName(t *testing.T) {
|
|
got := fileNameFromDAVProp("My File", "/remote.php/dav/files/u/x%20y")
|
|
if got != "My File" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestFileNameFromDAVPropDecodesHref(t *testing.T) {
|
|
got := fileNameFromDAVProp("", "/remote.php/dav/files/u/Report%20Q1.pdf")
|
|
if got != "Report Q1.pdf" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestWebDAVPathEncodesSpaces(t *testing.T) {
|
|
c := &Client{}
|
|
got := c.WebDAVPath("user@example.com", "/Documents/My File")
|
|
want := "/remote.php/dav/files/user@example.com/Documents/My%20File"
|
|
if got != want {
|
|
t.Fatalf("WebDAVPath() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolvePropfindClientPathRelativeHref(t *testing.T) {
|
|
got := ResolvePropfindClientPath("/Documents", "photo.jpg", "photo.jpg")
|
|
want := "/Documents/photo.jpg"
|
|
if got != want {
|
|
t.Fatalf("ResolvePropfindClientPath() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeClientFilePathStripsOCSPrefix(t *testing.T) {
|
|
got := NormalizeClientFilePath("alice", "/alice/files/Photos/vacation.jpg")
|
|
want := "/Photos/vacation.jpg"
|
|
if got != want {
|
|
t.Fatalf("NormalizeClientFilePath() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestEnsureClientFilePathJoinsName(t *testing.T) {
|
|
got := EnsureClientFilePath("/Documents", "report.pdf")
|
|
want := "/Documents/report.pdf"
|
|
if got != want {
|
|
t.Fatalf("EnsureClientFilePath() = %q, want %q", got, want)
|
|
}
|
|
}
|