2017-04-10 18:54:12 +02:00
|
|
|
package runtime
|
2016-12-15 11:10:09 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-03-03 16:19:35 +01:00
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
2016-12-15 11:10:09 +01: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 09:52:39 +01:00
|
|
|
assert.Len(stats.Models, 2)
|
2016-12-15 11:10:09 +01:00
|
|
|
assert.EqualValues(2, stats.Models["TP-Link 841"])
|
|
|
|
assert.EqualValues(1, stats.Models["Xeon Multi-Core"])
|
|
|
|
|
|
|
|
// check firmwares
|
2017-03-06 09:52:39 +01:00
|
|
|
assert.Len(stats.Firmwares, 1)
|
2016-12-15 11:10:09 +01:00
|
|
|
assert.EqualValues(1, stats.Firmwares["2016.1.6+entenhausen1"])
|
|
|
|
}
|
|
|
|
|
|
|
|
func createTestNodes() *Nodes {
|
|
|
|
nodes := NewNodes(&Config{})
|
|
|
|
|
|
|
|
nodeData := &data.ResponseData{
|
|
|
|
Statistics: &data.Statistics{
|
2017-03-14 08:54:46 +01:00
|
|
|
Clients: &data.Clients{
|
2016-12-15 11:10:09 +01:00
|
|
|
Total: 23,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NodeInfo: &data.NodeInfo{
|
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
2017-03-16 23:30:55 +01:00
|
|
|
Software: data.Software{
|
|
|
|
Firmware: &struct {
|
|
|
|
Base string `json:"base,omitempty"`
|
|
|
|
Release string `json:"release,omitempty"`
|
|
|
|
}{
|
|
|
|
Base: "2016.1.6",
|
|
|
|
Release: "2016.1.6+entenhausen1",
|
|
|
|
},
|
|
|
|
},
|
2016-12-15 11:10:09 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
nodes.Update("abcdef012345", nodeData)
|
|
|
|
|
|
|
|
nodes.Update("112233445566", &data.ResponseData{
|
|
|
|
Statistics: &data.Statistics{
|
2017-03-14 08:54:46 +01:00
|
|
|
Clients: &data.Clients{
|
2016-12-15 11:10:09 +01:00
|
|
|
Total: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NodeInfo: &data.NodeInfo{
|
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
nodes.Update("0xdeadbeef0x", &data.ResponseData{
|
|
|
|
NodeInfo: &data.NodeInfo{
|
|
|
|
VPN: true,
|
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "Xeon Multi-Core",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|