mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 11:01:49 +01:00
[PORT] Add cache test for admins (#31265)
* the cache was not refactored in Forgejo * fix the test modifying a global variable
This commit is contained in:
parent
77da92f42a
commit
9c48511c69
2 changed files with 8 additions and 6 deletions
11
modules/cache/cache.go
vendored
11
modules/cache/cache.go
vendored
|
@ -6,6 +6,7 @@ package cache
|
|||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
|
@ -46,7 +47,7 @@ const (
|
|||
)
|
||||
|
||||
func Test() (time.Duration, error) {
|
||||
if defaultCache == nil {
|
||||
if conn == nil {
|
||||
return 0, fmt.Errorf("default cache not initialized")
|
||||
}
|
||||
|
||||
|
@ -54,14 +55,14 @@ func Test() (time.Duration, error) {
|
|||
|
||||
start := time.Now()
|
||||
|
||||
if err := defaultCache.Delete(testCacheKey); err != nil {
|
||||
if err := conn.Delete(testCacheKey); err != nil {
|
||||
return 0, fmt.Errorf("expect cache to delete data based on key if exist but got: %w", err)
|
||||
}
|
||||
if err := defaultCache.Put(testCacheKey, testData, 10); err != nil {
|
||||
if err := conn.Put(testCacheKey, testData, 10); err != nil {
|
||||
return 0, fmt.Errorf("expect cache to store data but got: %w", err)
|
||||
}
|
||||
testVal, hit := defaultCache.Get(testCacheKey)
|
||||
if !hit {
|
||||
testVal := conn.Get(testCacheKey)
|
||||
if testVal == nil {
|
||||
return 0, fmt.Errorf("expect cache hit but got none")
|
||||
}
|
||||
if testVal != testData {
|
||||
|
|
3
modules/cache/cache_test.go
vendored
3
modules/cache/cache_test.go
vendored
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -35,7 +36,7 @@ func TestNewContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTest(t *testing.T) {
|
||||
defaultCache = nil
|
||||
defer test.MockVariableValue(&conn, nil)()
|
||||
_, err := Test()
|
||||
assert.Error(t, err)
|
||||
|
||||
|
|
Loading…
Reference in a new issue