mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-01 08:13:09 +08:00
expose hosterrorscache.Cache as an interface (#2291)
* expose hosterrorscache as an interface, change signature to capture the error reason * use the hosterrorscache.CacheInterface as struct field so users of Nuclei embedded can provide their own cache implementation Co-authored-by: Mike Rheinheimer <mrheinheimer@atlassian.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package hosterrorscache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -9,20 +10,20 @@ import (
|
||||
func TestCacheCheckMarkFailed(t *testing.T) {
|
||||
cache := New(3, DefaultMaxHostsCount)
|
||||
|
||||
cache.MarkFailed("http://example.com:80")
|
||||
cache.MarkFailed("http://example.com:80", fmt.Errorf("no address found for host"))
|
||||
if value, err := cache.failedTargets.Get("http://example.com:80"); err == nil && value != nil {
|
||||
require.Equal(t, 1, value, "could not get correct number of marked failed hosts")
|
||||
}
|
||||
cache.MarkFailed("example.com:80")
|
||||
cache.MarkFailed("example.com:80", fmt.Errorf("Client.Timeout exceeded while awaiting headers"))
|
||||
if value, err := cache.failedTargets.Get("example.com:80"); err == nil && value != nil {
|
||||
require.Equal(t, 2, value, "could not get correct number of marked failed hosts")
|
||||
}
|
||||
cache.MarkFailed("example.com")
|
||||
cache.MarkFailed("example.com", fmt.Errorf("could not resolve host"))
|
||||
if value, err := cache.failedTargets.Get("example.com"); err == nil && value != nil {
|
||||
require.Equal(t, 1, value, "could not get correct number of marked failed hosts")
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
cache.MarkFailed("test")
|
||||
cache.MarkFailed("test", fmt.Errorf("could not resolve host"))
|
||||
}
|
||||
|
||||
value := cache.Check("test")
|
||||
|
||||
Reference in New Issue
Block a user