Skip to content

Commit

Permalink
home: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Jun 21, 2023
1 parent d37c9fd commit 7806c92
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions internal/home/dns_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package home

import (
"net"
"testing"

"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/schedule"
"github.com/stretchr/testify/require"
)

func TestApplyAdditionalFiltering(t *testing.T) {
filtering.InitModule()

var (
globalIDs = []string{"ok"}
clientIDs = []string{"ok", "mail_ru", "vk"}

err error
)

Context.filters, err = filtering.New(&filtering.Config{
BlockedServices: &filtering.BlockedServices{
Schedule: schedule.EmptyWeekly(),
IDs: globalIDs,
},
}, nil)
require.NoError(t, err)

Context.clients.idIndex = map[string]*Client{
"client_1": {
UseOwnBlockedServices: false,
},
"client_2": {
UseOwnBlockedServices: true,
},
"client_3": {
BlockedServices: clientIDs,
UseOwnBlockedServices: true,
},
}

testCases := []struct {
name string
ip net.IP
id string
setts *filtering.Settings
wantLen int
}{{
name: "global_settings",
id: "client_1",
wantLen: len(globalIDs),
}, {
name: "custom_settings",
id: "client_2",
wantLen: 0,
}, {
name: "custom_settings_block",
id: "client_3",
wantLen: len(clientIDs),
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
setts := &filtering.Settings{}

applyAdditionalFiltering(net.IP{1, 2, 3, 4}, tc.id, setts)
require.Len(t, setts.ServicesRules, tc.wantLen)
})
}
}

0 comments on commit 7806c92

Please sign in to comment.