mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Feat: cache in-memory store
This commit is contained in:
@@ -12,18 +12,33 @@ import (
|
||||
func TestGetPolicyByID(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"name", "type", "options"}).
|
||||
AddRow("默认存储策略", "local", "{\"op_name\":\"123\"}")
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND \\(\\(`policies`.`id` = 1\\)\\)(.+)$").WillReturnRows(rows)
|
||||
policy, err := GetPolicyByID(uint(1))
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("默认存储策略", policy.Name)
|
||||
asserts.Equal("123", policy.OptionsSerialized.OPName)
|
||||
// 缓存未命中
|
||||
{
|
||||
rows := sqlmock.NewRows([]string{"name", "type", "options"}).
|
||||
AddRow("默认存储策略", "local", "{\"op_name\":\"123\"}")
|
||||
mock.ExpectQuery("^SELECT(.+)").WillReturnRows(rows)
|
||||
policy, err := GetPolicyByID(uint(22))
|
||||
asserts.NoError(err)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.Equal("默认存储策略", policy.Name)
|
||||
asserts.Equal("123", policy.OptionsSerialized.OPName)
|
||||
|
||||
rows = sqlmock.NewRows([]string{"name", "type", "options"})
|
||||
mock.ExpectQuery("^SELECT(.+)").WillReturnRows(rows)
|
||||
policy, err = GetPolicyByID(uint(23))
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.Error(err)
|
||||
}
|
||||
|
||||
// 命中
|
||||
{
|
||||
policy, err := GetPolicyByID(uint(22))
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("默认存储策略", policy.Name)
|
||||
asserts.Equal("123", policy.OptionsSerialized.OPName)
|
||||
|
||||
}
|
||||
|
||||
rows = sqlmock.NewRows([]string{"name", "type", "options"})
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND \\(\\(`policies`.`id` = 1\\)\\)(.+)$").WillReturnRows(rows)
|
||||
policy, err = GetPolicyByID(uint(1))
|
||||
asserts.Error(err)
|
||||
}
|
||||
|
||||
func TestPolicy_BeforeSave(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user