mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-27 00:49:41 -05:00
+10








3c02eedca6
Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Gabriel Górski <me@glaeqen.eu> Co-authored-by: Joel Godfrey <82655889+BaccanoMob@users.noreply.github.com> Co-authored-by: Shane Chiu <71911511+pwn2ooown@users.noreply.github.com> Co-authored-by: carloda <35763669+carloda@users.noreply.github.com> Co-authored-by: Taufik Hidayat <taufikdev88@gmail.com> Co-authored-by: Stephan Paternotte <Stephan-P@users.noreply.github.com> Co-authored-by: SIDDHU SINGH <siddhu3116@gmail.com> Co-authored-by: Gaurav Kalal <117557391+Gorupa@users.noreply.github.com> Co-authored-by: Nebula <40148908+nebula-it@users.noreply.github.com> Co-authored-by: Juan Soler <juansoler@gmail.com> Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com> Co-authored-by: Anatolii Prylutskyi <anpryl@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Graham Steffaniak <graham@debian-lake.ghome.net> Co-authored-by: Neil <kylelzzz02@icloud.com> Co-authored-by: Graham <info@quantumx-apps.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package activity
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gtsteffaniak/filebrowser/backend/internal/database/users"
|
|
)
|
|
|
|
func TestTrimPathForUserScope(t *testing.T) {
|
|
tests := []struct {
|
|
path string
|
|
scope string
|
|
want string
|
|
}{
|
|
{path: "/users/alice/docs/file.txt", scope: "/users/alice", want: "/docs/file.txt"},
|
|
{path: "/source/users/graham/path/to/file", scope: "/source/users/graham", want: "/path/to/file"},
|
|
{path: "/users/alice", scope: "/users/alice", want: "/"},
|
|
{path: "/docs/file.txt", scope: "/users/alice", want: "/docs/file.txt"},
|
|
{path: "/docs/file.txt", scope: "/", want: "/docs/file.txt"},
|
|
{path: "", scope: "/users/alice", want: ""},
|
|
}
|
|
for _, tc := range tests {
|
|
got := TrimPathForUserScope(tc.path, tc.scope)
|
|
if got != tc.want {
|
|
t.Fatalf("TrimPathForUserScope(%q, %q) = %q, want %q", tc.path, tc.scope, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFrontendEntryTrimPathsForUser(t *testing.T) {
|
|
actor := &users.User{
|
|
ID: 1,
|
|
BackendScopes: []users.BackendScope{
|
|
{Path: "/data", Scope: "/users/alice"},
|
|
},
|
|
}
|
|
fe := FrontendEntry{
|
|
Source: "/data",
|
|
Path: "/users/alice/docs/readme.txt",
|
|
Details: FrontendDetails{
|
|
Source: "/data",
|
|
Paths: []string{"/users/alice/docs/a.txt", "/users/alice/docs/b.txt"},
|
|
},
|
|
}
|
|
fe.TrimPathsForUser(actor)
|
|
if fe.Path != "/docs/readme.txt" {
|
|
t.Fatalf("Path = %q, want /docs/readme.txt", fe.Path)
|
|
}
|
|
if fe.Details.Paths[0] != "/docs/a.txt" || fe.Details.Paths[1] != "/docs/b.txt" {
|
|
t.Fatalf("Details.Paths = %#v", fe.Details.Paths)
|
|
}
|
|
}
|