[TEST] improve runtime
This commit is contained in:
parent
ccdeccd48f
commit
6e745bf78f
|
@ -55,8 +55,8 @@ func TestLoadAndSave(t *testing.T) {
|
||||||
// not autoload without StatePath
|
// not autoload without StatePath
|
||||||
NewNodes(config)
|
NewNodes(config)
|
||||||
|
|
||||||
// Test unmarshalable /dev/null - autolead with StatePath
|
// Test unmarshalable
|
||||||
config.StatePath = "/dev/null"
|
config.StatePath = "testdata/nodes-broken.json"
|
||||||
nodes := NewNodes(config)
|
nodes := NewNodes(config)
|
||||||
// Test unopen able
|
// Test unopen able
|
||||||
config.StatePath = "/root/nodes.json"
|
config.StatePath = "/root/nodes.json"
|
||||||
|
@ -71,8 +71,8 @@ func TestLoadAndSave(t *testing.T) {
|
||||||
os.Remove(tmpfile.Name())
|
os.Remove(tmpfile.Name())
|
||||||
|
|
||||||
assert.Panics(func() {
|
assert.Panics(func() {
|
||||||
SaveJSON(nodes, "/dev/null")
|
SaveJSON(nodes, "/proc/a")
|
||||||
// "open /dev/null.tmp: permission denied",
|
// "open /proc/a.tmp: permission denied",
|
||||||
})
|
})
|
||||||
|
|
||||||
tmpfile, _ = ioutil.TempFile("/tmp", "nodes")
|
tmpfile, _ = ioutil.TempFile("/tmp", "nodes")
|
||||||
|
@ -162,6 +162,14 @@ func TestLinksNodes(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.Len(nodes.List, 0)
|
assert.Len(nodes.List, 0)
|
||||||
|
|
||||||
|
nodes.Update("f4f26dd7a300", &data.ResponseData{
|
||||||
|
Nodeinfo: &data.Nodeinfo{
|
||||||
|
NodeID: "f4f26dd7a300",
|
||||||
|
Network: data.Network{
|
||||||
|
Mac: "f4:f2:6d:d7:a3:00",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
nodes.Update("f4f26dd7a30a", &data.ResponseData{
|
nodes.Update("f4f26dd7a30a", &data.ResponseData{
|
||||||
Nodeinfo: &data.Nodeinfo{
|
Nodeinfo: &data.Nodeinfo{
|
||||||
NodeID: "f4f26dd7a30a",
|
NodeID: "f4f26dd7a30a",
|
||||||
|
@ -169,11 +177,37 @@ func TestLinksNodes(t *testing.T) {
|
||||||
Mac: "f4:f2:6d:d7:a3:0a",
|
Mac: "f4:f2:6d:d7:a3:0a",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Neighbours: &data.Neighbours{
|
||||||
|
NodeID: "f4f26dd7a30a",
|
||||||
|
Babel: map[string]data.BabelNeighbours{
|
||||||
|
"vx_mesh_lan": {
|
||||||
|
LinkLocalAddress: "fe80::2",
|
||||||
|
Neighbours: map[string]data.BabelLink{
|
||||||
|
"fe80::1337": {
|
||||||
|
Cost: 26214,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
nodes.Update("f4f26dd7a30b", &data.ResponseData{
|
nodes.Update("f4f26dd7a30b", &data.ResponseData{
|
||||||
Nodeinfo: &data.Nodeinfo{
|
Nodeinfo: &data.Nodeinfo{
|
||||||
NodeID: "f4f26dd7a30b",
|
NodeID: "f4f26dd7a30b",
|
||||||
|
Network: data.Network{
|
||||||
|
Mesh: map[string]*data.NetworkInterface{
|
||||||
|
"babel": {
|
||||||
|
Interfaces: struct {
|
||||||
|
Wireless []string `json:"wireless,omitempty"`
|
||||||
|
Other []string `json:"other,omitempty"`
|
||||||
|
Tunnel []string `json:"tunnel,omitempty"`
|
||||||
|
}{
|
||||||
|
Other: []string{"fe80::1337"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Neighbours: &data.Neighbours{
|
Neighbours: &data.Neighbours{
|
||||||
NodeID: "f4f26dd7a30b",
|
NodeID: "f4f26dd7a30b",
|
||||||
|
@ -189,21 +223,35 @@ func TestLinksNodes(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
node := nodes.List["f4f26dd7a30a"]
|
// no neighbours nodeid
|
||||||
|
node := nodes.List["f4f26dd7a300"]
|
||||||
assert.NotNil(node)
|
assert.NotNil(node)
|
||||||
links := nodes.NodeLinks(node)
|
links := nodes.NodeLinks(node)
|
||||||
assert.Len(links, 0)
|
assert.Len(links, 0)
|
||||||
|
|
||||||
node = nodes.List["f4f26dd7a30b"]
|
// babel link
|
||||||
|
node = nodes.List["f4f26dd7a30a"]
|
||||||
assert.NotNil(node)
|
assert.NotNil(node)
|
||||||
links = nodes.NodeLinks(node)
|
links = nodes.NodeLinks(node)
|
||||||
assert.Len(links, 1)
|
assert.Len(links, 1)
|
||||||
link := links[0]
|
link := links[0]
|
||||||
assert.Equal(link.SourceID, "f4f26dd7a30b")
|
assert.Equal("f4f26dd7a30a", link.SourceID)
|
||||||
assert.Equal(link.SourceAddress, "f4:f2:6d:d7:a3:0b")
|
assert.Equal("fe80::2", link.SourceAddress)
|
||||||
assert.Equal(link.TargetID, "f4f26dd7a30a")
|
assert.Equal("f4f26dd7a30b", link.TargetID)
|
||||||
assert.Equal(link.TargetAddress, "f4:f2:6d:d7:a3:0a")
|
assert.Equal("fe80::1337", link.TargetAddress)
|
||||||
assert.Equal(link.TQ, float32(0.8))
|
assert.Equal(float32(0.6), link.TQ)
|
||||||
|
|
||||||
|
// batman link
|
||||||
|
node = nodes.List["f4f26dd7a30b"]
|
||||||
|
assert.NotNil(node)
|
||||||
|
links = nodes.NodeLinks(node)
|
||||||
|
assert.Len(links, 1)
|
||||||
|
link = links[0]
|
||||||
|
assert.Equal("f4f26dd7a30b", link.SourceID)
|
||||||
|
assert.Equal("f4:f2:6d:d7:a3:0b", link.SourceAddress)
|
||||||
|
assert.Equal("f4f26dd7a30a", link.TargetID)
|
||||||
|
assert.Equal("f4:f2:6d:d7:a3:0a", link.TargetAddress)
|
||||||
|
assert.Equal(float32(0.8), link.TQ)
|
||||||
|
|
||||||
nodeid := nodes.GetNodeIDbyAddress("f4:f2:6d:d7:a3:0a")
|
nodeid := nodes.GetNodeIDbyAddress("f4:f2:6d:d7:a3:0a")
|
||||||
assert.Equal("f4f26dd7a30a", nodeid)
|
assert.Equal("f4f26dd7a30a", nodeid)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
// make it invalid by this comment
|
||||||
|
"affe": 3
|
||||||
|
}
|
Loading…
Reference in New Issue