mirror of
https://github.com/cloudreve/Cloudreve.git
synced 2026-11-17 22:58:07 +00:00
Feat: cache in-memory store
This commit is contained in:
1 parent
5d50e7ed1e
commit
7375cc01f1
8 files changed
+134
-26
No files matched your search
+26
-11
@@ -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