From d9265aa9a8c21d97206b0e43a03b448f2c33a510 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 23 Jul 2019 20:01:50 +0300 Subject: [PATCH] fix tests --- dnsfilter/dnsfilter_test.go | 23 ++++++++++------------- dnsforward/dnsforward_test.go | 4 ++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dnsfilter/dnsfilter_test.go b/dnsfilter/dnsfilter_test.go index bf1f3df4..7b78b7a5 100644 --- a/dnsfilter/dnsfilter_test.go +++ b/dnsfilter/dnsfilter_test.go @@ -26,13 +26,13 @@ import ( func purgeCaches() { if gctx.safebrowsingCache != nil { - gctx.safebrowsingCache.Purge() + gctx.safebrowsingCache.Reset() } if gctx.parentalCache != nil { - gctx.parentalCache.Purge() + gctx.parentalCache.Reset() } if gctx.safeSearchCache != nil { - gctx.safeSearchCache.Purge() + gctx.safeSearchCache.Reset() } } @@ -44,6 +44,11 @@ func _Func() string { } func NewForTest(c *Config, filters map[int]string) *Dnsfilter { + if c != nil { + c.SafeBrowsingCacheSize = 1024 + c.SafeSearchCacheSize = 1024 + c.ParentalCacheSize = 1024 + } d := New(c, filters) purgeCaches() return d @@ -269,11 +274,7 @@ func TestSafeSearchCacheYandex(t *testing.T) { } // Check cache - cachedValue, isFound, err := getCachedReason(gctx.safeSearchCache, domain) - - if err != nil { - t.Fatalf("An error occured during cache search for %s: %s", domain, err) - } + cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) if !isFound { t.Fatalf("Safesearch cache doesn't work for %s!", domain) @@ -330,11 +331,7 @@ func TestSafeSearchCacheGoogle(t *testing.T) { } // Check cache - cachedValue, isFound, err := getCachedReason(gctx.safeSearchCache, domain) - - if err != nil { - t.Fatalf("An error occured during cache search for %s: %s", domain, err) - } + cachedValue, isFound := getCachedResult(gctx.safeSearchCache, domain) if !isFound { t.Fatalf("Safesearch cache doesn't work for %s!", domain) diff --git a/dnsforward/dnsforward_test.go b/dnsforward/dnsforward_test.go index 6b685510..d190ea37 100644 --- a/dnsforward/dnsforward_test.go +++ b/dnsforward/dnsforward_test.go @@ -458,6 +458,10 @@ func createTestServer(t *testing.T) *Server { s.conf.FilteringConfig.SafeBrowsingEnabled = true s.conf.Filters = make([]dnsfilter.Filter, 0) + s.conf.SafeBrowsingCacheSize = 1024 + s.conf.SafeSearchCacheSize = 1024 + s.conf.ParentalCacheSize = 1024 + rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n" filter := dnsfilter.Filter{ID: 0, Data: []byte(rules)} s.conf.Filters = append(s.conf.Filters, filter)