-
Notifications
You must be signed in to change notification settings - Fork 0
/
notif_operations_test.go
80 lines (71 loc) · 2.63 KB
/
notif_operations_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package netconf
import (
"context"
"regexp"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCreateSubscription(t *testing.T) {
start := time.Date(2023, time.June, 07, 18, 31, 48, 00, time.UTC)
end := time.Date(2023, time.June, 07, 18, 33, 48, 00, time.UTC)
tt := []struct {
name string
options []CreateSubscriptionOption
matches []*regexp.Regexp
}{
{
name: "noOptions",
matches: []*regexp.Regexp{
regexp.MustCompile(`<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"></create-subscription>`),
},
},
{
name: "startTime option",
options: []CreateSubscriptionOption{WithStartTimeOption(start)},
matches: []*regexp.Regexp{
regexp.MustCompile(`<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><startTime>` + regexp.QuoteMeta(start.Format(time.RFC3339)) + `</startTime></create-subscription>`),
},
},
{
name: "endTime option",
options: []CreateSubscriptionOption{WithStopTimeOption(end)},
matches: []*regexp.Regexp{
regexp.MustCompile(`<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><stopTime>` + regexp.QuoteMeta(end.Format(time.RFC3339)) + `</stopTime></create-subscription>`),
},
},
{
name: "stream option",
options: []CreateSubscriptionOption{WithStreamOption("thestream")},
matches: []*regexp.Regexp{
regexp.MustCompile(`<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><stream>thestream</stream></create-subscription>`),
},
},
{
name: "stream option and filter",
options: []CreateSubscriptionOption{
WithStreamOption("NETCONF"),
WithFilterOption(`<netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"/>`),
},
matches: []*regexp.Regexp{
regexp.MustCompile(`<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><stream>NETCONF</stream><filter type="subtree"><netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"/></filter></create-subscription>`),
},
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
ts := newTestServer(t)
sess := newSession(ts.transport())
sess.serverCaps = newCapabilitySet(NotificationCapability)
go sess.recv()
ts.queueRespString(`<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"><ok/></rpc-reply>`)
err := sess.CreateSubscription(context.Background(), tc.options...)
assert.NoError(t, err)
sentMsg, err := ts.popReq()
assert.NoError(t, err)
for _, match := range tc.matches {
assert.Regexp(t, match, string(sentMsg))
}
})
}
}