mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: pkg/task / Fix: failed test due to policy cache
This commit is contained in:
@@ -77,9 +77,9 @@ func (policy *Policy) AfterFind() (err error) {
|
||||
// 解析存储策略设置到OptionsSerialized
|
||||
if policy.Options != "" {
|
||||
err = json.Unmarshal([]byte(policy.Options), &policy.OptionsSerialized)
|
||||
if policy.OptionsSerialized.FileType == nil {
|
||||
policy.OptionsSerialized.FileType = []string{}
|
||||
}
|
||||
}
|
||||
if policy.OptionsSerialized.FileType == nil {
|
||||
policy.OptionsSerialized.FileType = []string{}
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
func TestGetPolicyByID(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
cache.Deletes([]string{"22", "23"}, "policy_")
|
||||
// 缓存未命中
|
||||
{
|
||||
rows := sqlmock.NewRows([]string{"name", "type", "options"}).
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestGetUserByID(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
cache.Deletes([]string{"1"}, "policy_")
|
||||
//找到用户时
|
||||
userRows := sqlmock.NewRows([]string{"id", "deleted_at", "email", "options", "group_id"}).
|
||||
AddRow(1, nil, "admin@cloudreve.org", "{}", 1)
|
||||
@@ -104,6 +104,7 @@ func TestNewUser(t *testing.T) {
|
||||
|
||||
func TestUser_AfterFind(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
cache.Deletes([]string{"1"}, "policy_")
|
||||
|
||||
policyRows := sqlmock.NewRows([]string{"id", "name"}).
|
||||
AddRow(1, "默认存储策略")
|
||||
@@ -198,6 +199,7 @@ func TestUser_GetRemainingCapacity(t *testing.T) {
|
||||
func TestUser_DeductionCapacity(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
cache.Deletes([]string{"1"}, "policy_")
|
||||
userRows := sqlmock.NewRows([]string{"id", "deleted_at", "storage", "options", "group_id"}).
|
||||
AddRow(1, nil, 0, "{}", 1)
|
||||
mock.ExpectQuery("^SELECT (.+)").WillReturnRows(userRows)
|
||||
|
||||
Reference in New Issue
Block a user