mirror of
https://github.com/fabriziosalmi/caddy-waf.git
synced 2025-12-23 14:17:45 -05:00
40 lines
801 B
Go
40 lines
801 B
Go
package caddywaf
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewRuleCache(t *testing.T) {
|
|
cache := NewRuleCache()
|
|
if cache == nil {
|
|
t.Fatal("NewRuleCache() returned nil")
|
|
}
|
|
if cache.rules == nil {
|
|
t.Fatal("NewRuleCache() created a cache with nil rules map")
|
|
}
|
|
}
|
|
|
|
func TestRuleCache_GetSet(t *testing.T) {
|
|
cache := NewRuleCache()
|
|
testRegex := regexp.MustCompile(`test.*`)
|
|
|
|
// Test Set
|
|
cache.Set("rule1", testRegex)
|
|
|
|
// Test Get
|
|
got, exists := cache.Get("rule1")
|
|
if !exists {
|
|
t.Error("RuleCache.Get() returned exists=false for existing rule")
|
|
}
|
|
if got != testRegex {
|
|
t.Error("RuleCache.Get() returned wrong regex")
|
|
}
|
|
|
|
// Test Get for non-existent rule
|
|
_, exists = cache.Get("nonexistent")
|
|
if exists {
|
|
t.Error("RuleCache.Get() returned exists=true for non-existent rule")
|
|
}
|
|
}
|