2017-05-20 12:46:29 +00: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)
|
|
|
|
|
|
|
|
nodes := runtime.NewNodes(&runtime.Config{})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 19:29:00 +00:00
|
|
|
Online: true,
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "node_a",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:a:mac",
|
|
|
|
Mesh: map[string]*data.BatInterface{
|
|
|
|
"bat0": &data.BatInterface{
|
|
|
|
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{
|
|
|
|
"node:a:mac:wifi": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:b:mac:wifi": data.BatmanLink{Tq: 153},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"node:a:mac:lan": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:b:mac:lan": data.BatmanLink{Tq: 51},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 19:29:00 +00:00
|
|
|
Online: true,
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "node_c",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:c:mac",
|
|
|
|
Mesh: map[string]*data.BatInterface{
|
|
|
|
"bat0": &data.BatInterface{
|
|
|
|
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{
|
|
|
|
"node:c:mac:lan": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:b:mac:lan": data.BatmanLink{Tq: 102},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 19:29:00 +00:00
|
|
|
Online: true,
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "node_b",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:b:mac",
|
|
|
|
Mesh: map[string]*data.BatInterface{
|
|
|
|
"bat0": &data.BatInterface{
|
|
|
|
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{
|
|
|
|
"node:b:mac:lan": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:c:mac:lan": data.BatmanLink{Tq: 204},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"node:b:mac:wifi": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:a:mac:wifi": data.BatmanLink{Tq: 204},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-11-01 19:29:00 +00:00
|
|
|
nodes.AddNode(&runtime.Node{
|
|
|
|
Online: false,
|
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "node_d",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:d:mac",
|
|
|
|
Mesh: map[string]*data.BatInterface{
|
|
|
|
"bat0": &data.BatInterface{
|
|
|
|
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{
|
|
|
|
"node:d:mac:lan": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:c:mac:lan": data.BatmanLink{Tq: 204},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"node:d:mac:wifi": data.BatadvNeighbours{
|
|
|
|
Neighbours: map[string]data.BatmanLink{
|
|
|
|
"node:a:mac:wifi": data.BatmanLink{Tq: 204},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-05-20 12:46:29 +00:00
|
|
|
|
|
|
|
meshviewer := transform(nodes)
|
|
|
|
assert.NotNil(meshviewer)
|
2017-11-01 19:29:00 +00:00
|
|
|
assert.Len(meshviewer.Nodes, 4)
|
2017-05-20 12:46:29 +00:00
|
|
|
links := meshviewer.Links
|
|
|
|
assert.Len(links, 3)
|
|
|
|
|
|
|
|
for _, link := range links {
|
|
|
|
switch link.SourceMAC {
|
|
|
|
case "node:a:mac:lan":
|
|
|
|
assert.Equal("other", link.Type)
|
|
|
|
assert.Equal("node:b:mac:lan", link.TargetMAC)
|
|
|
|
assert.Equal(float32(0.2), link.SourceTQ)
|
|
|
|
assert.Equal(float32(0.2), link.TargetTQ)
|
|
|
|
break
|
|
|
|
|
|
|
|
case "node:a:mac:wifi":
|
|
|
|
assert.Equal("wifi", link.Type)
|
|
|
|
assert.Equal("node:b:mac:wifi", link.TargetMAC)
|
|
|
|
assert.Equal(float32(0.6), link.SourceTQ)
|
|
|
|
assert.Equal(float32(0.8), link.TargetTQ)
|
2017-12-31 04:26:17 +00:00
|
|
|
case "node:b:mac:lan":
|
2017-05-20 12:46:29 +00:00
|
|
|
assert.Equal("other", link.Type)
|
|
|
|
assert.Equal("node:c:mac:lan", link.TargetMAC)
|
|
|
|
assert.Equal(float32(0.8), link.SourceTQ)
|
|
|
|
assert.Equal(float32(0.4), link.TargetTQ)
|
|
|
|
break
|
2017-12-31 04:26:17 +00:00
|
|
|
default:
|
|
|
|
assert.False(true, "invalid link.SourceMAC found")
|
2017-05-20 12:46:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|