mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
Merge branch 'master' into custom/filtered-routes-from-communities
This commit is contained in:
commit
1d0b28b354
2 changed files with 44 additions and 0 deletions
|
@ -92,6 +92,7 @@ func fromCacheMemory(key string) (Parsed, bool) {
|
|||
}
|
||||
|
||||
func fromCacheRedis(key string) (Parsed, bool) {
|
||||
key = "B" + IPVersion + "_" + key
|
||||
val, err := CacheRedis.Get(key)
|
||||
if err != nil {
|
||||
return NilParse, false
|
||||
|
@ -121,6 +122,7 @@ func toCacheMemory(key string, val Parsed) {
|
|||
}
|
||||
|
||||
func toCacheRedis(key string, val Parsed) {
|
||||
key = "B" + IPVersion + "_" + key
|
||||
val["ttl"] = time.Now().Add(5 * time.Minute)
|
||||
err := CacheRedis.Set(key, val)
|
||||
if err != nil {
|
||||
|
|
|
@ -56,3 +56,45 @@ func Test_RedisCacheAccessKeyMissing(t *testing.T) {
|
|||
t.Log("Cache error:", err)
|
||||
t.Log(parsed)
|
||||
}
|
||||
|
||||
func Test_RedisCacheRoutes(t *testing.T) {
|
||||
f, err := openFile("routes_bird1_ipv4.sample")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
parsed := parseRoutes(f)
|
||||
_, ok := parsed["routes"].([]Parsed)
|
||||
if !ok {
|
||||
t.Fatal("Error getting routes")
|
||||
}
|
||||
|
||||
cache, err := NewRedisCache(CacheConfig{
|
||||
RedisServer: "localhost:6379",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Log("Redis server not available:", err)
|
||||
t.Log("Skipping redis tests.")
|
||||
return
|
||||
}
|
||||
|
||||
err = cache.Set("routes_protocol_test", parsed)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
parsed, err = cache.Get("routes_protocol_test")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
routes, ok := parsed["routes"].([]interface{})
|
||||
if !ok {
|
||||
t.Error("Error getting routes")
|
||||
}
|
||||
|
||||
t.Log("Retrieved routes:", len(routes))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue