2017-05-20 14:46:29 +02:00
|
|
|
package meshviewerFFRGB
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTransform(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2018-01-07 21:00:56 +01:00
|
|
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
2017-05-20 14:46:29 +02:00
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_a",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:a:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Wireless: []string{"node:a:mac:wifi"},
|
|
|
|
Tunnel: []string{"node:a:mac:vpn"},
|
|
|
|
Other: []string{"node:a:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_a",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:wifi": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:wifi": {Tq: 153},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:lan": {Tq: 51},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_c",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:c:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Other: []string{"node:c:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_b",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:c:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:lan": {Tq: 102},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_b",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:b:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Wireless: []string{"node:b:mac:wifi"},
|
|
|
|
Other: []string{"node:b:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_b",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:c:mac:lan": {Tq: 204},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:wifi": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:wifi": {Tq: 204},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-11-01 20:29:00 +01:00
|
|
|
nodes.AddNode(&runtime.Node{
|
|
|
|
Online: false,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-11-01 20:29:00 +01:00
|
|
|
NodeID: "node_d",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:d:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Wireless: []string{"node:b:mac:wifi"},
|
|
|
|
Other: []string{"node:b:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_d",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:d:mac:lan": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:c:mac:lan": {Tq: 204},
|
2017-11-01 20:29:00 +01:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:d:mac:wifi": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:wifi": {Tq: 204},
|
2017-11-01 20:29:00 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-05-20 14:46:29 +02:00
|
|
|
|
|
|
|
meshviewer := transform(nodes)
|
|
|
|
assert.NotNil(meshviewer)
|
2017-11-01 20:29:00 +01:00
|
|
|
assert.Len(meshviewer.Nodes, 4)
|
2017-05-20 14:46:29 +02:00
|
|
|
links := meshviewer.Links
|
|
|
|
assert.Len(links, 3)
|
|
|
|
|
|
|
|
for _, link := range links {
|
2017-12-05 23:17:49 +01:00
|
|
|
switch link.SourceAddress {
|
2017-05-20 14:46:29 +02:00
|
|
|
case "node:a:mac:lan":
|
|
|
|
assert.Equal("other", link.Type)
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.Equal("node:b:mac:lan", link.TargetAddress)
|
2017-05-20 14:46:29 +02:00
|
|
|
assert.Equal(float32(0.2), link.SourceTQ)
|
2018-10-07 20:04:36 +02:00
|
|
|
assert.Equal(float32(0), link.TargetTQ)
|
2017-05-20 14:46:29 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
case "node:a:mac:wifi":
|
|
|
|
assert.Equal("wifi", link.Type)
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.Equal("node:b:mac:wifi", link.TargetAddress)
|
2017-05-20 14:46:29 +02:00
|
|
|
assert.Equal(float32(0.6), link.SourceTQ)
|
|
|
|
assert.Equal(float32(0.8), link.TargetTQ)
|
2017-12-31 05:26:17 +01:00
|
|
|
case "node:b:mac:lan":
|
2017-05-20 14:46:29 +02:00
|
|
|
assert.Equal("other", link.Type)
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.Equal("node:c:mac:lan", link.TargetAddress)
|
2017-05-20 14:46:29 +02:00
|
|
|
assert.Equal(float32(0.8), link.SourceTQ)
|
|
|
|
assert.Equal(float32(0.4), link.TargetTQ)
|
|
|
|
break
|
2017-12-31 05:26:17 +01:00
|
|
|
default:
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.False(true, "invalid link.SourceAddress found")
|
2017-05-20 14:46:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|