File: xfrm_monitor_test.go

package info (click to toggle)
golang-github-vishvananda-netlink 1.0.0+git20181030.023a6da-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 928 kB
  • sloc: makefile: 25
file content (39 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// +build linux

package netlink

import (
	"testing"

	"github.com/vishvananda/netlink/nl"
)

func TestXfrmMonitorExpire(t *testing.T) {
	defer setUpNetlinkTest(t)()

	ch := make(chan XfrmMsg)
	done := make(chan struct{})
	defer close(done)
	errChan := make(chan error)
	if err := XfrmMonitor(ch, nil, errChan, nl.XFRM_MSG_EXPIRE); err != nil {
		t.Fatal(err)
	}

	// Program state with limits
	state := getBaseState()
	state.Limits.TimeHard = 2
	state.Limits.TimeSoft = 1
	if err := XfrmStateAdd(state); err != nil {
		t.Fatal(err)
	}

	msg := (<-ch).(*XfrmMsgExpire)
	if msg.XfrmState.Spi != state.Spi || msg.Hard {
		t.Fatal("Received unexpected msg")
	}

	msg = (<-ch).(*XfrmMsgExpire)
	if msg.XfrmState.Spi != state.Spi || !msg.Hard {
		t.Fatal("Received unexpected msg")
	}
}