Fix review comments

Fixed coredns plugin tests
Check that user filter is not empty
This commit is contained in:
Andrey Meshkov 2018-10-30 11:01:09 +03:00
parent 32d4e80c93
commit 760e3596b6
4 changed files with 22 additions and 12 deletions

3
app.go
View File

@ -149,6 +149,7 @@ func main() {
filter := &config.Filters[i] filter := &config.Filters[i]
err = filter.load() err = filter.load()
if err != nil { if err != nil {
// This is okay for the first start, the filter will be loaded later
log.Printf("Couldn't load filter %d contents due to %s", filter.ID, err) log.Printf("Couldn't load filter %d contents due to %s", filter.ID, err)
} }
} }
@ -264,7 +265,7 @@ func upgradeConfig() error {
} }
if config.SchemaVersion > SchemaVersion { if config.SchemaVersion > SchemaVersion {
// Unexpected -- config file is newer than the // Unexpected -- the config file is newer than we expect
return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion) return fmt.Errorf("configuration file is supposed to be used with a newer version of AdGuard Home, schema=%d", config.SchemaVersion)
} }

View File

@ -244,10 +244,9 @@ func generateCoreDNSConfigText() (string, error) {
// first of all, append the user filter // first of all, append the user filter
userFilter := getUserFilter() userFilter := getUserFilter()
// TODO: Don't add if empty if len(userFilter.contents) > 0 {
//if len(userFilter.contents) > 0 {
filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()}) filters = append(filters, coreDnsFilter{ID: userFilter.ID, Path: userFilter.getFilterFilePath()})
//} }
// then go through other filters // then go through other filters
for i := range config.Filters { for i := range config.Filters {

View File

@ -185,7 +185,7 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
} }
count++ count++
} }
log.Printf("Added %d rules from %d", count, filter.ID) log.Printf("Added %d rules from filter ID=%d", count, filter.ID)
if err = scanner.Err(); err != nil { if err = scanner.Err(); err != nil {
return nil, err return nil, err

View File

@ -15,17 +15,26 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
) )
// TODO: Change tests -- there's new config template now
func TestSetup(t *testing.T) { func TestSetup(t *testing.T) {
for i, testcase := range []struct { for i, testcase := range []struct {
config string config string
failing bool failing bool
}{ }{
{`dnsfilter`, false}, {`dnsfilter`, false},
{`dnsfilter /dev/nonexistent/abcdef`, true}, {`dnsfilter {
{`dnsfilter ../tests/dns.txt`, false}, filter 0 /dev/nonexistent/abcdef
{`dnsfilter ../tests/dns.txt { safebrowsing }`, false}, }`, true},
{`dnsfilter ../tests/dns.txt { parental }`, true}, {`dnsfilter {
filter 0 ../tests/dns.txt
}`, false},
{`dnsfilter {
safebrowsing
filter 0 ../tests/dns.txt
}`, false},
{`dnsfilter {
parental
filter 0 ../tests/dns.txt
}`, true},
} { } {
c := caddy.NewTestController("dns", testcase.config) c := caddy.NewTestController("dns", testcase.config)
err := setup(c) err := setup(c)
@ -56,7 +65,8 @@ func TestEtcHostsFilter(t *testing.T) {
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
c := caddy.NewTestController("dns", fmt.Sprintf("dnsfilter %s", tmpfile.Name())) configText := fmt.Sprintf("dnsfilter {\nfilter 0 %s\n}", tmpfile.Name())
c := caddy.NewTestController("dns", configText)
p, err := setupPlugin(c) p, err := setupPlugin(c)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)