test: add driver and account test
This commit is contained in:
41
internal/operations/account_test.go
Normal file
41
internal/operations/account_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package operations_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
store.Init(db)
|
||||
}
|
||||
|
||||
func TestCreateAccount(t *testing.T) {
|
||||
var accounts = []struct {
|
||||
account model.Account
|
||||
iserr bool
|
||||
}{
|
||||
{account: model.Account{Driver: "Local", VirtualPath: "/local", Addition: "{}"}, iserr: false},
|
||||
{account: model.Account{Driver: "Local", VirtualPath: "/local", Addition: "{}"}, iserr: true},
|
||||
{account: model.Account{Driver: "None", VirtualPath: "/none", Addition: "{}"}, iserr: true},
|
||||
}
|
||||
for _, account := range accounts {
|
||||
err := operations.CreateAccount(context.Background(), account.account)
|
||||
if err != nil {
|
||||
if !account.iserr {
|
||||
t.Errorf("failed to create account: %+v", err)
|
||||
} else {
|
||||
t.Logf("expect failed to create account: %+v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,10 @@ func GetDriverNew(name string) (New, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func GetDriverItemsMap() map[string]driver.Items {
|
||||
return driverItemsMap
|
||||
}
|
||||
|
||||
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||
tAddition := reflect.TypeOf(addition)
|
||||
mainItems := getMainItems(config)
|
||||
|
17
internal/operations/driver_test.go
Normal file
17
internal/operations/driver_test.go
Normal file
@ -0,0 +1,17 @@
|
||||
package operations_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "github.com/alist-org/alist/v3/drivers"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
)
|
||||
|
||||
func TestDriverItemsMap(t *testing.T) {
|
||||
itemsMap := operations.GetDriverItemsMap()
|
||||
if len(itemsMap) != 0 {
|
||||
t.Logf("driverItemsMap: %v", itemsMap)
|
||||
} else {
|
||||
t.Errorf("expected driverItemsMap not empty, but got empty")
|
||||
}
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var db gorm.DB
|
||||
|
||||
func Init(dbgorm *gorm.DB) {
|
||||
db = *dbgorm
|
||||
db.AutoMigrate(&model.Account{})
|
||||
}
|
||||
|
Reference in New Issue
Block a user