"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "internal/querylog/qlog_file_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_file_test.go  (AdGuardHome-0.104.1):qlog_file_test.go  (AdGuardHome-0.104.3)
skipping to change at line 246 skipping to change at line 246
} }
// prepareTestFiles - prepares several test query log files // prepareTestFiles - prepares several test query log files
// each of them -- with the specified linesCount // each of them -- with the specified linesCount
func prepareTestFiles(dir string, filesCount, linesCount int) []string { func prepareTestFiles(dir string, filesCount, linesCount int) []string {
format := `{"IP":"${IP}","T":"${TIMESTAMP}","QH":"example.org","QT":"A"," QC":"IN","Answer":"AAAAAAABAAEAAAAAB2V4YW1wbGUDb3JnAAABAAEHZXhhbXBsZQNvcmcAAAEAA QAAAAAABAECAwQ=","Result":{},"Elapsed":0,"Upstream":"upstream"}` format := `{"IP":"${IP}","T":"${TIMESTAMP}","QH":"example.org","QT":"A"," QC":"IN","Answer":"AAAAAAABAAEAAAAAB2V4YW1wbGUDb3JnAAABAAEHZXhhbXBsZQNvcmcAAAEAA QAAAAAABAECAwQ=","Result":{},"Elapsed":0,"Upstream":"upstream"}`
lineTime, _ := time.Parse(time.RFC3339Nano, "2020-02-18T22:36:35.920973+0 3:00") lineTime, _ := time.Parse(time.RFC3339Nano, "2020-02-18T22:36:35.920973+0 3:00")
lineIP := uint32(0) lineIP := uint32(0)
files := make([]string, 0) files := make([]string, filesCount)
for j := 0; j < filesCount; j++ { for j := 0; j < filesCount; j++ {
f, _ := ioutil.TempFile(dir, "*.txt") f, _ := ioutil.TempFile(dir, "*.txt")
files = append(files, f.Name()) files[filesCount-j-1] = f.Name()
for i := 0; i < linesCount; i++ { for i := 0; i < linesCount; i++ {
lineIP += 1 lineIP += 1
lineTime = lineTime.Add(time.Second) lineTime = lineTime.Add(time.Second)
ip := make(net.IP, 4) ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, lineIP) binary.BigEndian.PutUint32(ip, lineIP)
line := format line := format
line = strings.ReplaceAll(line, "${IP}", ip.String()) line = strings.ReplaceAll(line, "${IP}", ip.String())
skipping to change at line 292 skipping to change at line 292
assert.Nil(t, err) assert.Nil(t, err)
defer q.Close() defer q.Close()
target, _ := time.Parse(time.RFC3339, "2020-08-31T18:44:25.376690873+03:0 0") target, _ := time.Parse(time.RFC3339, "2020-08-31T18:44:25.376690873+03:0 0")
_, depth, err := q.Seek(target.UnixNano()) _, depth, err := q.Seek(target.UnixNano())
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 1, depth) assert.Equal(t, 1, depth)
} }
func TestQLogSeek_ErrEndOfLog(t *testing.T) { func TestQLogSeek_ErrTSTooLate(t *testing.T) {
testDir := prepareTestDir() testDir := prepareTestDir()
t.Cleanup(func() { t.Cleanup(func() {
_ = os.RemoveAll(testDir) _ = os.RemoveAll(testDir)
}) })
d := `{"T":"2020-08-31T18:44:23.911246629+03:00","QH":"wfqvjymurpwegyv"," QT":"A","QC":"IN","CP":"","Answer":"","Result":{},"Elapsed":66286385,"Upstream": "tls://dns-unfiltered.adguard.com:853"} d := `{"T":"2020-08-31T18:44:23.911246629+03:00","QH":"wfqvjymurpwegyv"," QT":"A","QC":"IN","CP":"","Answer":"","Result":{},"Elapsed":66286385,"Upstream": "tls://dns-unfiltered.adguard.com:853"}
{"T":"2020-08-31T18:44:25.376690873+03:00"} {"T":"2020-08-31T18:44:25.376690873+03:00"}
{"T":"2020-08-31T18:44:25.382540454+03:00"} {"T":"2020-08-31T18:44:25.382540454+03:00"}
` `
f, err := ioutil.TempFile(testDir, "*.txt") f, err := ioutil.TempFile(testDir, "*.txt")
skipping to change at line 317 skipping to change at line 317
assert.Nil(t, err) assert.Nil(t, err)
q, err := NewQLogFile(f.Name()) q, err := NewQLogFile(f.Name())
assert.Nil(t, err) assert.Nil(t, err)
defer q.Close() defer q.Close()
target, err := time.Parse(time.RFC3339, "2020-08-31T18:44:25.382540454+03 :00") target, err := time.Parse(time.RFC3339, "2020-08-31T18:44:25.382540454+03 :00")
assert.Nil(t, err) assert.Nil(t, err)
_, depth, err := q.Seek(target.UnixNano() + int64(time.Second)) _, depth, err := q.Seek(target.UnixNano() + int64(time.Second))
assert.Equal(t, ErrEndOfLog, err) assert.Equal(t, ErrTSTooLate, err)
assert.Equal(t, 2, depth) assert.Equal(t, 2, depth)
} }
func TestQLogSeek_ErrTSTooEarly(t *testing.T) {
testDir := prepareTestDir()
t.Cleanup(func() {
_ = os.RemoveAll(testDir)
})
d := `{"T":"2020-08-31T18:44:23.911246629+03:00","QH":"wfqvjymurpwegyv","
QT":"A","QC":"IN","CP":"","Answer":"","Result":{},"Elapsed":66286385,"Upstream":
"tls://dns-unfiltered.adguard.com:853"}
{"T":"2020-08-31T18:44:25.376690873+03:00"}
{"T":"2020-08-31T18:44:25.382540454+03:00"}
`
f, err := ioutil.TempFile(testDir, "*.txt")
assert.Nil(t, err)
defer f.Close()
_, err = f.WriteString(d)
assert.Nil(t, err)
q, err := NewQLogFile(f.Name())
assert.Nil(t, err)
defer q.Close()
target, err := time.Parse(time.RFC3339, "2020-08-31T18:44:23.911246629+03
:00")
assert.Nil(t, err)
_, depth, err := q.Seek(target.UnixNano() - int64(time.Second))
assert.Equal(t, ErrTSTooEarly, err)
assert.Equal(t, 1, depth)
}
 End of changes. 5 change blocks. 
4 lines changed or deleted 4 lines changed or added

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