-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
60 lines (56 loc) · 1.23 KB
/
server_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
package netconf
import (
"testing"
"github.com/freeconf/restconf"
"github.com/freeconf/restconf/device"
"github.com/freeconf/restconf/estream"
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/node"
"github.com/freeconf/yang/nodeutil"
"github.com/freeconf/yang/source"
)
func TestServer(t *testing.T) {
ypath := source.Any(
restconf.InternalYPath,
restconf.InternalIetfRfcYPath,
source.Dir("./yang"),
)
streams := estream.NewService()
d := device.New(ypath)
s := NewServer(d, streams)
d.Add("fc-netconf", Api(s))
b, err := d.Browser("fc-netconf")
fc.RequireEqual(t, nil, err)
err = b.Root().UpdateFrom(readJson(`
{
"ssh": {
"options" : {
"port" : "127.0.0.1:9000",
"hostKeyFile" : "testdata/host.key"
}
}
}
`))
fc.AssertEqual(t, nil, err)
fc.AssertEqual(t, true, s.sshHandler.Status().Running)
// configure again to test service live re-config
err = b.Root().UpdateFrom(readJson(`
{
"ssh": {
"options" : {
"port" : "127.0.0.1:9001",
"hostKeyFile" : "testdata/host.key"
}
}
}
`))
fc.AssertEqual(t, nil, err)
fc.AssertEqual(t, true, s.sshHandler.Status().Running)
}
func readJson(s string) node.Node {
n, err := nodeutil.ReadJSON(s)
if err != nil {
panic(err)
}
return n
}