Add: proc comm test

This commit is contained in:
ignatella 2024-11-04 18:49:25 +01:00
parent a77a91fb46
commit 7014843161
2 changed files with 12 additions and 4 deletions

View File

@ -198,7 +198,7 @@ func NewMonitor(opts ...MonitorOption) *Monitor {
}
func (monitor *Monitor) monitor() {
changesEvents := make([]*MonitorEvent, 0)
var changesEvents []*MonitorEvent
for {
msgs, err := monitor.conn.Receive()
@ -220,7 +220,7 @@ func (monitor *Monitor) monitor() {
GeneratedBy: event,
Changes: changesEvents,
}
changesEvents = make([]*MonitorEvent, 0)
changesEvents = nil
break
}
@ -333,7 +333,6 @@ func (monitor *Monitor) Close() error {
// handle, for now.
func (cc *Conn) AddMonitor(monitor *Monitor) (chan *MonitorEvent, error) {
generationalEventCh, err := cc.AddGenerationalMonitor(monitor)
if err != nil {
return nil, err
}

View File

@ -4,6 +4,8 @@ import (
"fmt"
"log"
"net"
"os"
"path/filepath"
"sync"
"sync/atomic"
"testing"
@ -46,7 +48,6 @@ func TestMonitor(t *testing.T) {
// Clear all rules at the beginning + end of the test.
c.FlushRuleset()
defer c.FlushRuleset()
// default to monitor all
monitor := nftables.NewMonitor()
events, err := c.AddGenerationalMonitor(monitor)
@ -69,6 +70,14 @@ func TestMonitor(t *testing.T) {
return
}
genMsg := event.GeneratedBy.Data.(*nftables.GenMsg)
fileName := filepath.Base(os.Args[0])
if genMsg.ProcComm != fileName {
err = fmt.Errorf("procComm: %s, want: %s", genMsg.ProcComm, fileName)
return
}
for _, change := range event.Changes {
if change.Error != nil {
err = fmt.Errorf("monitor err: %s", change.Error)