Skip to content

Commit

Permalink
[TEST] improve runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed May 19, 2019
1 parent 099b0dd commit e3024e4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
66 changes: 57 additions & 9 deletions runtime/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestLoadAndSave(t *testing.T) {
// not autoload without StatePath
NewNodes(config)

// Test unmarshalable /proc/a - autolead with StatePath
config.StatePath = "/proc/a"
// Test unmarshalable
config.StatePath = "testdata/nodes-broken.json"
nodes := NewNodes(config)
// Test unopen able
config.StatePath = "/root/nodes.json"
Expand Down Expand Up @@ -162,18 +162,52 @@ func TestLinksNodes(t *testing.T) {
}
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{
Nodeinfo: &data.Nodeinfo{
NodeID: "f4f26dd7a30a",
Network: data.Network{
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{
Nodeinfo: &data.Nodeinfo{
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{
NodeID: "f4f26dd7a30b",
Expand All @@ -189,21 +223,35 @@ func TestLinksNodes(t *testing.T) {
},
})

node := nodes.List["f4f26dd7a30a"]
// no neighbours nodeid
node := nodes.List["f4f26dd7a300"]
assert.NotNil(node)
links := nodes.NodeLinks(node)
assert.Len(links, 0)

node = nodes.List["f4f26dd7a30b"]
// babel link
node = nodes.List["f4f26dd7a30a"]
assert.NotNil(node)
links = nodes.NodeLinks(node)
assert.Len(links, 1)
link := links[0]
assert.Equal(link.SourceID, "f4f26dd7a30b")
assert.Equal(link.SourceAddress, "f4:f2:6d:d7:a3:0b")
assert.Equal(link.TargetID, "f4f26dd7a30a")
assert.Equal(link.TargetAddress, "f4:f2:6d:d7:a3:0a")
assert.Equal(link.TQ, float32(0.8))
assert.Equal("f4f26dd7a30a", link.SourceID)
assert.Equal("fe80::2", link.SourceAddress)
assert.Equal("f4f26dd7a30b", link.TargetID)
assert.Equal("fe80::1337", link.TargetAddress)
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")
assert.Equal("f4f26dd7a30a", nodeid)
Expand Down
4 changes: 4 additions & 0 deletions runtime/testdata/nodes-broken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// make it invalid by this comment
"affe": 3
}

0 comments on commit e3024e4

Please sign in to comment.