Add nflog TestQuery (#1070)

This commit is contained in:
Jose Donizetti 2017-11-01 17:38:00 -02:00 committed by stuart nelson
parent f8dc12c317
commit 511c6bcb6a
1 changed files with 33 additions and 0 deletions

View File

@ -273,3 +273,36 @@ func TestNilGossipDoesNotCrash(t *testing.T) {
err = nl.Log(&pb.Receiver{}, "key", []uint64{}, []uint64{}) err = nl.Log(&pb.Receiver{}, "key", []uint64{}, []uint64{})
require.NoError(t, err, "logging notification failed") require.NoError(t, err, "logging notification failed")
} }
func TestQuery(t *testing.T) {
nl, err := New()
if err != nil {
require.NoError(t, err, "constructing nflog failed")
}
recv := new(pb.Receiver)
// no key param
_, err = nl.Query(QGroupKey("key"))
require.EqualError(t, err, "no query parameters specified")
// no recv param
_, err = nl.Query(QReceiver(recv))
require.EqualError(t, err, "no query parameters specified")
// no entry
_, err = nl.Query(QGroupKey("nonexistingkey"), QReceiver(recv))
require.EqualError(t, err, "not found")
// existing entry
firingAlerts := []uint64{1, 2, 3}
resolvedAlerts := []uint64{4, 5}
err = nl.Log(recv, "key", firingAlerts, resolvedAlerts)
require.NoError(t, err, "logging notification failed")
entries, err := nl.Query(QGroupKey("key"), QReceiver(recv))
entry := entries[0]
require.EqualValues(t, firingAlerts, entry.FiringAlerts)
require.EqualValues(t, resolvedAlerts, entry.ResolvedAlerts)
}