"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "internal/querylog/qlog_reader_test.go" between
AdGuardHome-0.104.1.tar.gz and AdGuardHome-0.104.3.tar.gz

About: AdGuard Home is a network-wide ads & trackers blocking DNS server. It operates as a DNS server that re-routes tracking domains to a "black hole," thus preventing your devices from connecting to those servers.

qlog_reader_test.go  (AdGuardHome-0.104.1):qlog_reader_test.go  (AdGuardHome-0.104.3)
package querylog package querylog
import ( import (
"errors"
"io" "io"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestQLogReaderEmpty(t *testing.T) { func TestQLogReaderEmpty(t *testing.T) {
r, err := NewQLogReader([]string{}) r, err := NewQLogReader([]string{})
skipping to change at line 93 skipping to change at line 94
if err == nil { if err == nil {
assert.True(t, len(line) > 0) assert.True(t, len(line) > 0)
read += 1 read += 1
} }
} }
assert.Equal(t, count*filesCount, read) assert.Equal(t, count*filesCount, read)
assert.Equal(t, io.EOF, err) assert.Equal(t, io.EOF, err)
} }
func TestQLogReader_Seek(t *testing.T) {
count := 10000
filesCount := 2
testDir := prepareTestDir()
t.Cleanup(func() {
_ = os.RemoveAll(testDir)
})
testFiles := prepareTestFiles(testDir, filesCount, count)
r, err := NewQLogReader(testFiles)
assert.Nil(t, err)
assert.NotNil(t, r)
t.Cleanup(func() {
_ = r.Close()
})
testCases := []struct {
name string
time string
want error
}{{
name: "not_too_old",
time: "2020-02-19T04:04:56.920973+03:00",
want: nil,
}, {
name: "old",
time: "2020-02-19T01:28:16.920973+03:00",
want: nil,
}, {
name: "first",
time: "2020-02-19T04:09:55.920973+03:00",
want: nil,
}, {
name: "last",
time: "2020-02-19T01:23:16.920973+03:00",
want: nil,
}, {
name: "non-existent_long_ago",
time: "2000-02-19T01:23:16.920973+03:00",
want: ErrTSTooEarly,
}, {
name: "non-existent_far_ahead",
time: "2100-02-19T01:23:16.920973+03:00",
want: nil,
}, {
name: "non-existent_but_could",
time: "2020-02-18T22:36:37.000000+03:00",
want: ErrTSNotFound,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
timestamp, err := time.Parse(time.RFC3339Nano, tc.time)
assert.Nil(t, err)
err = r.Seek(timestamp.UnixNano())
assert.True(t, errors.Is(err, tc.want), err)
})
}
}
func TestQLogReader_ReadNext(t *testing.T) {
count := 10
filesCount := 1
testDir := prepareTestDir()
t.Cleanup(func() {
_ = os.RemoveAll(testDir)
})
testFiles := prepareTestFiles(testDir, filesCount, count)
r, err := NewQLogReader(testFiles)
assert.Nil(t, err)
assert.NotNil(t, r)
t.Cleanup(func() {
_ = r.Close()
})
testCases := []struct {
name string
start int
want error
}{{
name: "ok",
start: 0,
want: nil,
}, {
name: "too_big",
start: count + 1,
want: io.EOF,
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := r.SeekStart()
assert.Nil(t, err, err)
for i := 1; i < tc.start; i++ {
_, err := r.ReadNext()
assert.Nil(t, err)
}
_, err = r.ReadNext()
assert.Equal(t, tc.want, err)
})
}
}
// TODO(e.burkov): Remove the tests below. Make tests above more compelling.
func TestQLogReaderSeek(t *testing.T) { func TestQLogReaderSeek(t *testing.T) {
// more or less big file // more or less big file
count := 10000 count := 10000
filesCount := 2 filesCount := 2
testDir := prepareTestDir() testDir := prepareTestDir()
defer func() { _ = os.RemoveAll(testDir) }() defer func() { _ = os.RemoveAll(testDir) }()
testFiles := prepareTestFiles(testDir, filesCount, count) testFiles := prepareTestFiles(testDir, filesCount, count)
r, err := NewQLogReader(testFiles) r, err := NewQLogReader(testFiles)
 End of changes. 2 change blocks. 
0 lines changed or deleted 111 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)