*(dnsforward): fix in-memory log entries sort orderr
This commit is contained in:
parent
87c0410914
commit
9d8a95f836
|
@ -206,7 +206,10 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} {
|
||||||
l.bufferLock.Lock()
|
l.bufferLock.Lock()
|
||||||
total += len(l.buffer)
|
total += len(l.buffer)
|
||||||
memoryEntries := make([]*logEntry, 0)
|
memoryEntries := make([]*logEntry, 0)
|
||||||
for _, entry := range l.buffer {
|
|
||||||
|
// go through the buffer in the reverse order
|
||||||
|
for i := len(l.buffer) - 1; i >= 0; i-- {
|
||||||
|
entry := l.buffer[i]
|
||||||
if !matchesGetDataParams(entry, params) {
|
if !matchesGetDataParams(entry, params) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ func TestQueryLog(t *testing.T) {
|
||||||
_ = l.flushLogBuffer(true)
|
_ = l.flushLogBuffer(true)
|
||||||
// add memory entries
|
// add memory entries
|
||||||
addEntry(l, "test.example.org", "1.1.1.3", "2.2.2.3")
|
addEntry(l, "test.example.org", "1.1.1.3", "2.2.2.3")
|
||||||
|
addEntry(l, "example.com", "1.1.1.4", "2.2.2.4")
|
||||||
|
|
||||||
// get all entries
|
// get all entries
|
||||||
params := getDataParams{
|
params := getDataParams{
|
||||||
|
@ -48,10 +49,11 @@ func TestQueryLog(t *testing.T) {
|
||||||
}
|
}
|
||||||
d := l.getData(params)
|
d := l.getData(params)
|
||||||
mdata := d["data"].([]map[string]interface{})
|
mdata := d["data"].([]map[string]interface{})
|
||||||
assert.Equal(t, 3, len(mdata))
|
assert.Equal(t, 4, len(mdata))
|
||||||
assert.True(t, checkEntry(t, mdata[0], "test.example.org", "1.1.1.3", "2.2.2.3"))
|
assert.True(t, checkEntry(t, mdata[0], "example.com", "1.1.1.4", "2.2.2.4"))
|
||||||
assert.True(t, checkEntry(t, mdata[1], "example.org", "1.1.1.2", "2.2.2.2"))
|
assert.True(t, checkEntry(t, mdata[1], "test.example.org", "1.1.1.3", "2.2.2.3"))
|
||||||
assert.True(t, checkEntry(t, mdata[2], "example.org", "1.1.1.1", "2.2.2.1"))
|
assert.True(t, checkEntry(t, mdata[2], "example.org", "1.1.1.2", "2.2.2.2"))
|
||||||
|
assert.True(t, checkEntry(t, mdata[3], "example.org", "1.1.1.1", "2.2.2.1"))
|
||||||
|
|
||||||
// search by domain (strict)
|
// search by domain (strict)
|
||||||
params = getDataParams{
|
params = getDataParams{
|
||||||
|
@ -96,10 +98,11 @@ func TestQueryLog(t *testing.T) {
|
||||||
}
|
}
|
||||||
d = l.getData(params)
|
d = l.getData(params)
|
||||||
mdata = d["data"].([]map[string]interface{})
|
mdata = d["data"].([]map[string]interface{})
|
||||||
assert.Equal(t, 3, len(mdata))
|
assert.Equal(t, 4, len(mdata))
|
||||||
assert.True(t, checkEntry(t, mdata[0], "test.example.org", "1.1.1.3", "2.2.2.3"))
|
assert.True(t, checkEntry(t, mdata[0], "example.com", "1.1.1.4", "2.2.2.4"))
|
||||||
assert.True(t, checkEntry(t, mdata[1], "example.org", "1.1.1.2", "2.2.2.2"))
|
assert.True(t, checkEntry(t, mdata[1], "test.example.org", "1.1.1.3", "2.2.2.3"))
|
||||||
assert.True(t, checkEntry(t, mdata[2], "example.org", "1.1.1.1", "2.2.2.1"))
|
assert.True(t, checkEntry(t, mdata[2], "example.org", "1.1.1.2", "2.2.2.2"))
|
||||||
|
assert.True(t, checkEntry(t, mdata[3], "example.org", "1.1.1.1", "2.2.2.1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func addEntry(l *queryLog, host, answerStr, client string) {
|
func addEntry(l *queryLog, host, answerStr, client string) {
|
||||||
|
|
Loading…
Reference in New Issue