mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 00:28:17 +00:00
Improve unit test for caching
- Configure `setting.CacheService.TTL` which will force the code to go trough the caching mechanism. - Remove the TODO and uncomment the test code.
This commit is contained in:
parent
6323c6d1a2
commit
2303421999
76
modules/cache/cache_test.go
vendored
76
modules/cache/cache_test.go
vendored
|
@ -18,6 +18,7 @@ func createTestCache() {
|
||||||
Adapter: "memory",
|
Adapter: "memory",
|
||||||
TTL: time.Minute,
|
TTL: time.Minute,
|
||||||
})
|
})
|
||||||
|
setting.CacheService.TTL = 30
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewContext(t *testing.T) {
|
func TestNewContext(t *testing.T) {
|
||||||
|
@ -54,12 +55,12 @@ func TestGetString(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "", data)
|
assert.Equal(t, "", data)
|
||||||
|
|
||||||
// data, err = GetString("key", func() (string, error) {
|
data, err = GetString("key", func() (string, error) {
|
||||||
// return "some data", nil
|
return "some data", nil
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.Equal(t, "", data)
|
assert.Equal(t, "", data)
|
||||||
// Remove("key")
|
Remove("key")
|
||||||
|
|
||||||
data, err = GetString("key", func() (string, error) {
|
data, err = GetString("key", func() (string, error) {
|
||||||
return "some data", nil
|
return "some data", nil
|
||||||
|
@ -67,13 +68,12 @@ func TestGetString(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "some data", data)
|
assert.Equal(t, "some data", data)
|
||||||
|
|
||||||
// data, err = GetString("key", func() (string, error) {
|
data, err = GetString("key", func() (string, error) {
|
||||||
// return "", fmt.Errorf("some error")
|
return "", fmt.Errorf("some error")
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.Equal(t, "some data", data)
|
assert.Equal(t, "some data", data)
|
||||||
|
Remove("key")
|
||||||
// TODO: uncommented code works in IDE but not with go test
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInt(t *testing.T) {
|
func TestGetInt(t *testing.T) {
|
||||||
|
@ -91,12 +91,12 @@ func TestGetInt(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 0, data)
|
assert.Equal(t, 0, data)
|
||||||
|
|
||||||
// data, err = GetInt("key", func() (int, error) {
|
data, err = GetInt("key", func() (int, error) {
|
||||||
// return 100, nil
|
return 100, nil
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.Equal(t, 0, data)
|
assert.Equal(t, 0, data)
|
||||||
// Remove("key")
|
Remove("key")
|
||||||
|
|
||||||
data, err = GetInt("key", func() (int, error) {
|
data, err = GetInt("key", func() (int, error) {
|
||||||
return 100, nil
|
return 100, nil
|
||||||
|
@ -104,13 +104,12 @@ func TestGetInt(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 100, data)
|
assert.Equal(t, 100, data)
|
||||||
|
|
||||||
// data, err = GetInt("key", func() (int, error) {
|
data, err = GetInt("key", func() (int, error) {
|
||||||
// return 0, fmt.Errorf("some error")
|
return 0, fmt.Errorf("some error")
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.Equal(t, 100, data)
|
assert.Equal(t, 100, data)
|
||||||
|
Remove("key")
|
||||||
// TODO: uncommented code works in IDE but not with go test
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInt64(t *testing.T) {
|
func TestGetInt64(t *testing.T) {
|
||||||
|
@ -128,12 +127,12 @@ func TestGetInt64(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 0, data)
|
assert.EqualValues(t, 0, data)
|
||||||
|
|
||||||
// data, err = GetInt64("key", func() (int64, error) {
|
data, err = GetInt64("key", func() (int64, error) {
|
||||||
// return 100, nil
|
return 100, nil
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.EqualValues(t, 0, data)
|
assert.EqualValues(t, 0, data)
|
||||||
// Remove("key")
|
Remove("key")
|
||||||
|
|
||||||
data, err = GetInt64("key", func() (int64, error) {
|
data, err = GetInt64("key", func() (int64, error) {
|
||||||
return 100, nil
|
return 100, nil
|
||||||
|
@ -141,11 +140,10 @@ func TestGetInt64(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 100, data)
|
assert.EqualValues(t, 100, data)
|
||||||
|
|
||||||
// data, err = GetInt64("key", func() (int, error) {
|
data, err = GetInt64("key", func() (int64, error) {
|
||||||
// return 0, fmt.Errorf("some error")
|
return 0, fmt.Errorf("some error")
|
||||||
// })
|
})
|
||||||
// assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// assert.EqualValues(t, 100, data)
|
assert.EqualValues(t, 100, data)
|
||||||
|
Remove("key")
|
||||||
// TODO: uncommented code works in IDE but not with go test
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue