2017-04-10 16:54:12 +00:00
|
|
|
package influxdb
|
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"
|
2017-04-10 16:54:12 +00:00
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
2016-12-15 10:10:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGlobalStats(t *testing.T) {
|
2017-04-10 16:54:12 +00:00
|
|
|
stats := runtime.NewGlobalStats(createTestNodes())
|
2016-12-15 10:10:09 +00:00
|
|
|
|
|
|
|
assert := assert.New(t)
|
2017-04-10 16:54:12 +00:00
|
|
|
fields := GlobalStatsFields(stats)
|
2017-01-20 22:23:31 +00:00
|
|
|
|
|
|
|
// check fields
|
|
|
|
assert.EqualValues(3, fields["nodes"])
|
2016-12-15 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
func createTestNodes() *runtime.Nodes {
|
|
|
|
nodes := runtime.NewNodes(&runtime.Config{})
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodeData := &runtime.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"
|
2017-11-14 18:33:50 +00:00
|
|
|
nodeData.Nodeinfo.Software.Autoupdater.Enabled = true
|
|
|
|
nodeData.Nodeinfo.Software.Autoupdater.Branch = "stable"
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(nodeData)
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&runtime.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-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&runtime.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
|
|
|
|
}
|