From e3024e4e1d5943e0aa8a288b18cb6287e7a44c29 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Sun, 19 May 2019 10:22:56 +0200 Subject: [PATCH] [TEST] improve runtime --- runtime/nodes_test.go | 66 ++++++++++++++++++++++++++---- runtime/testdata/nodes-broken.json | 4 ++ 2 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 runtime/testdata/nodes-broken.json diff --git a/runtime/nodes_test.go b/runtime/nodes_test.go index a2c9d7ad..a6c6c1d6 100644 --- a/runtime/nodes_test.go +++ b/runtime/nodes_test.go @@ -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" @@ -162,6 +162,14 @@ 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", @@ -169,11 +177,37 @@ func TestLinksNodes(t *testing.T) { 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", @@ -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) diff --git a/runtime/testdata/nodes-broken.json b/runtime/testdata/nodes-broken.json new file mode 100644 index 00000000..2ff2996a --- /dev/null +++ b/runtime/testdata/nodes-broken.json @@ -0,0 +1,4 @@ +{ + // make it invalid by this comment + "affe": 3 +}