mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-24 07:33:35 +08:00
fix breadcrumb
This commit is contained in:
@@ -13,6 +13,9 @@ type Breadcrumb struct {
|
|||||||
|
|
||||||
func ToBreadcrumb(fullpath string) (crumbs []Breadcrumb) {
|
func ToBreadcrumb(fullpath string) (crumbs []Breadcrumb) {
|
||||||
parts := strings.Split(fullpath, "/")
|
parts := strings.Split(fullpath, "/")
|
||||||
|
if fullpath == "/" {
|
||||||
|
parts = []string{""}
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(parts); i++ {
|
for i := 0; i < len(parts); i++ {
|
||||||
name := parts[i]
|
name := parts[i]
|
||||||
|
74
weed/server/filer_ui/breadcrumb_test.go
Normal file
74
weed/server/filer_ui/breadcrumb_test.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
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: "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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user