Skip to content

Commit

Permalink
querylog: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Feb 8, 2021
1 parent 55bde69 commit 091a698
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 459 deletions.
26 changes: 15 additions & 11 deletions internal/querylog/qlog_test.go
Expand Up @@ -14,16 +14,24 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestMain(m *testing.M) {
aghtest.DiscardLogOutput(m)
}

func prepareTestDir() string {
func prepareTestDir(t *testing.T) string {
t.Helper()

const dir = "./agh-test"
_ = os.RemoveAll(dir)
_ = os.MkdirAll(dir, 0o755)
assert.Nil(t, os.RemoveAll(dir))
require.Nil(t, os.MkdirAll(dir, 0o755))

t.Cleanup(func() {
assert.Nil(t, os.RemoveAll(dir))
})

return dir
}

Expand All @@ -35,8 +43,7 @@ func TestQueryLog(t *testing.T) {
Interval: 1,
MemSize: 100,
}
conf.BaseDir = prepareTestDir()
defer func() { _ = os.RemoveAll(conf.BaseDir) }()
conf.BaseDir = prepareTestDir(t)
l := newQueryLog(conf)

// add disk entries
Expand Down Expand Up @@ -118,8 +125,7 @@ func TestQueryLogOffsetLimit(t *testing.T) {
Interval: 1,
MemSize: 100,
}
conf.BaseDir = prepareTestDir()
defer func() { _ = os.RemoveAll(conf.BaseDir) }()
conf.BaseDir = prepareTestDir(t)
l := newQueryLog(conf)

// add 10 entries to the log
Expand Down Expand Up @@ -172,8 +178,7 @@ func TestQueryLogMaxFileScanEntries(t *testing.T) {
Interval: 1,
MemSize: 100,
}
conf.BaseDir = prepareTestDir()
defer func() { _ = os.RemoveAll(conf.BaseDir) }()
conf.BaseDir = prepareTestDir(t)
l := newQueryLog(conf)

// add 10 entries to the log
Expand All @@ -200,8 +205,7 @@ func TestQueryLogFileDisabled(t *testing.T) {
Interval: 1,
MemSize: 2,
}
conf.BaseDir = prepareTestDir()
defer func() { _ = os.RemoveAll(conf.BaseDir) }()
conf.BaseDir = prepareTestDir(t)
l := newQueryLog(conf)

addEntry(l, "example1.org", net.IPv4(1, 1, 1, 1), net.IPv4(2, 2, 2, 1))
Expand Down

0 comments on commit 091a698

Please sign in to comment.