Files
seaweedfs/weed/server/filer_ui/breadcrumb_test.go
Minsoo KimandGitHub a1e5eb9dad Fix UI prefix url encoding (#9344)
* Fix filer UI navigation for URL-sensitive object prefixes

* Fix filer UI navigation for URL-sensitive object prefixes

* Clarify filer UI path escaping test name

Rename the legacy filer UI
  path test to describe the actual behavior being checked.

  The printpath helper preserves timestamp characters that are valid in URL path
  components, while the PR fix is focused on query-string escaping for path and cursor
  parameters.
2026-05-06 19:14:36 -07:00

105 lines
1.7 KiB
Go

package filer_ui
import (
"reflect"
"testing"
)
func TestToBreadcrumb(t *testing.T) {
type args struct {
fullpath string
}
tests := []struct {
name string
args args
wantCrumbs []Breadcrumb
}{
{
name: "empty",
args: args{
fullpath: "",
},
wantCrumbs: []Breadcrumb{
{
Name: "/",
Link: "/",
},
},
},
{
name: "test1",
args: args{
fullpath: "/",
},
wantCrumbs: []Breadcrumb{
{
Name: "/",
Link: "/",
},
},
},
{
name: "test2",
args: args{
fullpath: "/abc",
},
wantCrumbs: []Breadcrumb{
{
Name: "/",
Link: "/",
},
{
Name: "abc",
Link: "/abc/",
},
},
},
{
name: "test3",
args: args{
fullpath: "/abc/def",
},
wantCrumbs: []Breadcrumb{
{
Name: "/",
Link: "/",
},
{
Name: "abc",
Link: "/abc/",
},
{
Name: "def",
Link: "/abc/def/",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotCrumbs := ToBreadcrumb(tt.args.fullpath); !reflect.DeepEqual(gotCrumbs, tt.wantCrumbs) {
t.Errorf("ToBreadcrumb() = %v, want %v", gotCrumbs, tt.wantCrumbs)
}
})
}
}
func TestPrintPathPreservesPathSafeTimestampChars(t *testing.T) {
got := printpath("/logs/run_id=backfill__2025-01-31T15:00:00+00:00/")
want := "/logs/run_id=backfill__2025-01-31T15:00:00+00:00/"
if got != want {
t.Fatalf("printpath() = %q, want %q", got, want)
}
}
func TestQueryEscapePreservesPlusInLoadMoreCursor(t *testing.T) {
got := funcMap["queryEscape"].(func(string) string)("task:1+next")
want := "task%3A1%2Bnext"
if got != want {
t.Fatalf("queryEscape() = %q, want %q", got, want)
}
}