Cache database size
This commit is contained in:
parent
c185d463e6
commit
bf404e65da
2 changed files with 59 additions and 12 deletions
28
stats_test.go
Normal file
28
stats_test.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// If the cache is less than 10 minutes old, return the cached data.
|
||||
func TestCacheLessThan10MinutesOld(t *testing.T) {
|
||||
result := GetDBSize()
|
||||
|
||||
// Assert that the size of the database is returned
|
||||
if result != cache.data {
|
||||
t.Errorf("Expected database size, but got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
// If the cache is more than 10 minutes old, return the size of the database.
|
||||
func TestCacheMoreThan10MinutesOld(t *testing.T) {
|
||||
// Set the cache timestamp to 11 minutes ago
|
||||
cache.timestamp = time.Now().Add(-11 * time.Minute)
|
||||
result := GetDBSize()
|
||||
|
||||
// Assert that the size of the database is returned
|
||||
if result != cache.data {
|
||||
t.Errorf("Expected database size, but got %s", result)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue