diff options
Diffstat (limited to 'internal/blocklist/blocklist_test.go')
| -rw-r--r-- | internal/blocklist/blocklist_test.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/internal/blocklist/blocklist_test.go b/internal/blocklist/blocklist_test.go index 9ae1749..b6d4e83 100644 --- a/internal/blocklist/blocklist_test.go +++ b/internal/blocklist/blocklist_test.go @@ -7,9 +7,14 @@ import ( ) func TestBlockZeroIP(t *testing.T) { +dir := t.TempDir() + p := filepath.Join(dir, "block.txt") + os.WriteFile(p, []byte("||example.com^\n0.0.0.0 doubleclick.net\n"), 0644) + b := New(ResponseZeroIP) - b.addRule("||example.com^") - b.addRule("0.0.0.0 doubleclick.net") + if err := b.LoadFile(p); err != nil { + t.Fatal(err) + } cases := []struct { domain string @@ -29,11 +34,15 @@ func TestBlockZeroIP(t *testing.T) { } } } - func TestException(t *testing.T) { + dir := t.TempDir() + p := filepath.Join(dir, "block.txt") + os.WriteFile(p, []byte("||example.com^\n@@||whitelist.example.com^\n"), 0644) + b := New(ResponseZeroIP) - b.addRule("||example.com^") - b.addRule("@@||whitelist.example.com^") + if err := b.LoadFile(p); err != nil { + t.Fatal(err) + } if !b.IsBlocked("example.com.") { t.Error("expected blocked") @@ -45,7 +54,6 @@ func TestException(t *testing.T) { t.Error("expected NOT blocked (exception subdomain)") } } - func TestLoadFile(t *testing.T) { dir := t.TempDir() p := filepath.Join(dir, "block.txt") |
