Cache database size

This commit is contained in:
Joakim Hellsén 2024-02-05 02:40:00 +01:00
commit bf404e65da
2 changed files with 59 additions and 12 deletions

28
stats_test.go Normal file
View 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)
}
}