2017-04-10 16:54:12 +00:00
|
|
|
package runtime
|
2016-12-15 10:10:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-03-03 15:19:35 +00:00
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
2016-12-15 10:10:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGlobalStats(t *testing.T) {
|
|
|
|
stats := NewGlobalStats(createTestNodes())
|
|
|
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
assert.EqualValues(1, stats.Gateways)
|
|
|
|
assert.EqualValues(3, stats.Nodes)
|
|
|
|
assert.EqualValues(25, stats.Clients)
|
|
|
|
|
|
|
|
// check models
|
2017-03-06 08:52:39 +00:00
|
|
|
assert.Len(stats.Models, 2)
|
2016-12-15 10:10:09 +00:00
|
|
|
assert.EqualValues(2, stats.Models["TP-Link 841"])
|
|
|
|
assert.EqualValues(1, stats.Models["Xeon Multi-Core"])
|
|
|
|
|
|
|
|
// check firmwares
|
2017-03-06 08:52:39 +00:00
|
|
|
assert.Len(stats.Firmwares, 1)
|
2016-12-15 10:10:09 +00:00
|
|
|
assert.EqualValues(1, stats.Firmwares["2016.1.6+entenhausen1"])
|
2017-11-14 18:33:50 +00:00
|
|
|
|
|
|
|
// check autoupdater
|
|
|
|
assert.Len(stats.Autoupdater, 2)
|
|
|
|
assert.EqualValues(1, stats.Autoupdater["stable"])
|
2016-12-15 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func createTestNodes() *Nodes {
|
|
|
|
nodes := NewNodes(&Config{})
|
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodeData := &Node{
|
|
|
|
Online: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 23,
|
|
|
|
},
|
|
|
|
},
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "abcdef012345",
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-05-20 12:46:29 +00:00
|
|
|
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
|
|
|
nodes.AddNode(nodeData)
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&Node{
|
|
|
|
Online: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 2,
|
|
|
|
},
|
|
|
|
},
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "112233445566",
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
2017-11-14 18:33:50 +00:00
|
|
|
Software: data.Software{
|
|
|
|
Autoupdater: struct {
|
|
|
|
Enabled bool `json:"enabled,omitempty"`
|
|
|
|
Branch string `json:"branch,omitempty"`
|
|
|
|
}{
|
|
|
|
Enabled: true,
|
|
|
|
Branch: "stable",
|
|
|
|
},
|
|
|
|
},
|
2016-12-15 10:10:09 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&Node{
|
|
|
|
Online: true,
|
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "0xdeadbeef0x",
|
|
|
|
VPN: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "Xeon Multi-Core",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|