mirror of https://github.com/Xhofe/alist
test: add `GetAccountVirtualFilesByPath` test
parent
097b516dc5
commit
5780d9d834
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -39,3 +40,34 @@ func TestCreateAccount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountVirtualFilesByPath(t *testing.T) {
|
||||
Setup(t)
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath("/a")
|
||||
var names []string
|
||||
for _, virtualFile := range virtualFiles {
|
||||
names = append(names, virtualFile.GetName())
|
||||
}
|
||||
var expectedNames = []string{"b", "c", "d"}
|
||||
if utils.SliceEqual(names, expectedNames) {
|
||||
t.Logf("passed")
|
||||
} else {
|
||||
t.Errorf("expected: %+v, got: %+v", expectedNames, names)
|
||||
}
|
||||
}
|
||||
|
||||
func Setup(t *testing.T) {
|
||||
var accounts = []model.Account{
|
||||
{Driver: "Local", VirtualPath: "/a/b", Index: 0, Addition: "{}"},
|
||||
{Driver: "Local", VirtualPath: "/a/c", Index: 1, Addition: "{}"},
|
||||
{Driver: "Local", VirtualPath: "/a/d", Index: 2, Addition: "{}"},
|
||||
{Driver: "Local", VirtualPath: "/a/d/e", Index: 3, Addition: "{}"},
|
||||
{Driver: "Local", VirtualPath: "/a/d/e.balance", Index: 4, Addition: "{}"},
|
||||
}
|
||||
for _, account := range accounts {
|
||||
err := operations.CreateAccount(context.Background(), account)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create account: %+v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package utils
|
||||
|
||||
func SliceEqual[T comparable](a, b []T) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, v := range a {
|
||||
if v != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue