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
|
|
|
)
|
|
|
|
|
2018-01-17 20:20:35 +01:00
|
|
|
const (
|
|
|
|
TEST_SITE = "ffhb"
|
|
|
|
TEST_DOMAIN = "city"
|
|
|
|
)
|
2017-11-21 15:12:06 +01:00
|
|
|
|
2016-12-15 11:10:09 +01:00
|
|
|
func TestGlobalStats(t *testing.T) {
|
2018-01-17 20:20:35 +01:00
|
|
|
stats := NewGlobalStats(createTestNodes(), map[string][]string{TEST_SITE: {TEST_DOMAIN}})
|
2016-12-15 11:10:09 +01:00
|
|
|
|
|
|
|
assert := assert.New(t)
|
2017-11-21 15:12:06 +01:00
|
|
|
assert.Len(stats, 2)
|
|
|
|
|
|
|
|
//check GLOBAL_SITE stats
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.EqualValues(1, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Gateways)
|
|
|
|
assert.EqualValues(3, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Nodes)
|
|
|
|
assert.EqualValues(25, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Clients)
|
2016-12-15 11:10:09 +01:00
|
|
|
|
|
|
|
// check models
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[GLOBAL_SITE][GLOBAL_DOMAIN].Models, 2)
|
|
|
|
assert.EqualValues(2, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Models["TP-Link 841"])
|
|
|
|
assert.EqualValues(1, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Models["Xeon Multi-Core"])
|
2016-12-15 11:10:09 +01:00
|
|
|
|
|
|
|
// check firmwares
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[GLOBAL_SITE][GLOBAL_DOMAIN].Firmwares, 1)
|
|
|
|
assert.EqualValues(1, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Firmwares["2016.1.6+entenhausen1"])
|
2017-11-14 19:33:50 +01:00
|
|
|
|
|
|
|
// check autoupdater
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[GLOBAL_SITE][GLOBAL_DOMAIN].Autoupdater, 2)
|
|
|
|
assert.EqualValues(1, stats[GLOBAL_SITE][GLOBAL_DOMAIN].Autoupdater["stable"])
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
// check TEST_SITE stats
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.EqualValues(1, stats[TEST_SITE][GLOBAL_DOMAIN].Gateways)
|
|
|
|
assert.EqualValues(2, stats[TEST_SITE][GLOBAL_DOMAIN].Nodes)
|
|
|
|
assert.EqualValues(23, stats[TEST_SITE][GLOBAL_DOMAIN].Clients)
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
// check models
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[TEST_SITE][GLOBAL_DOMAIN].Models, 2)
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][GLOBAL_DOMAIN].Models["TP-Link 841"])
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][GLOBAL_DOMAIN].Models["Xeon Multi-Core"])
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
// check firmwares
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[TEST_SITE][GLOBAL_DOMAIN].Firmwares, 1)
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][GLOBAL_DOMAIN].Firmwares["2016.1.6+entenhausen1"])
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
// check autoupdater
|
2018-01-17 20:20:35 +01:00
|
|
|
assert.Len(stats[TEST_SITE][GLOBAL_DOMAIN].Autoupdater, 1)
|
|
|
|
assert.EqualValues(0, stats[TEST_SITE][GLOBAL_DOMAIN].Autoupdater["stable"])
|
|
|
|
|
|
|
|
// check TEST_DOMAIN stats
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][TEST_DOMAIN].Gateways)
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][TEST_DOMAIN].Nodes)
|
|
|
|
assert.EqualValues(0, stats[TEST_SITE][TEST_DOMAIN].Clients)
|
|
|
|
|
|
|
|
// check models
|
|
|
|
assert.Len(stats[TEST_SITE][TEST_DOMAIN].Models, 1)
|
|
|
|
assert.EqualValues(0, stats[TEST_SITE][TEST_DOMAIN].Models["TP-Link 841"])
|
|
|
|
assert.EqualValues(1, stats[TEST_SITE][TEST_DOMAIN].Models["Xeon Multi-Core"])
|
|
|
|
|
|
|
|
// check firmwares
|
|
|
|
assert.Len(stats[TEST_SITE][TEST_DOMAIN].Firmwares, 0)
|
|
|
|
assert.EqualValues(0, stats[TEST_SITE][TEST_DOMAIN].Firmwares["2016.1.6+entenhausen1"])
|
|
|
|
|
|
|
|
// check autoupdater
|
|
|
|
assert.Len(stats[TEST_SITE][TEST_DOMAIN].Autoupdater, 1)
|
|
|
|
assert.EqualValues(0, stats[TEST_SITE][TEST_DOMAIN].Autoupdater["stable"])
|
2016-12-15 11:10:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func createTestNodes() *Nodes {
|
2018-01-07 21:00:56 +01:00
|
|
|
nodes := NewNodes(&NodesConfig{})
|
2016-12-15 11:10:09 +01:00
|
|
|
|
2017-05-20 14:46:29 +02:00
|
|
|
nodeData := &Node{
|
|
|
|
Online: true,
|
2016-12-15 11:10:09 +01:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 23,
|
|
|
|
},
|
|
|
|
},
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "abcdef012345",
|
2016-12-15 11:10:09 +01:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
2017-11-21 15:12:06 +01:00
|
|
|
System: data.System{
|
|
|
|
SiteCode: TEST_SITE,
|
|
|
|
},
|
2016-12-15 11:10:09 +01:00
|
|
|
},
|
|
|
|
}
|
2021-02-17 23:35:12 +01:00
|
|
|
nodeData.Nodeinfo.Software.Firmware = &struct {
|
|
|
|
Base string `json:"base,omitempty"`
|
|
|
|
Release string `json:"release,omitempty"`
|
|
|
|
}{
|
|
|
|
Release: "2016.1.6+entenhausen1",
|
|
|
|
}
|
2017-05-20 14:46:29 +02:00
|
|
|
nodes.AddNode(nodeData)
|
2016-12-15 11:10:09 +01:00
|
|
|
|
2017-05-20 14:46:29 +02:00
|
|
|
nodes.AddNode(&Node{
|
|
|
|
Online: true,
|
2016-12-15 11:10:09 +01:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 2,
|
|
|
|
},
|
|
|
|
},
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "112233445566",
|
2016-12-15 11:10:09 +01:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
2017-11-14 19:33:50 +01:00
|
|
|
Software: data.Software{
|
2021-02-17 23:35:12 +01:00
|
|
|
Autoupdater: &struct {
|
2017-11-14 19:33:50 +01:00
|
|
|
Enabled bool `json:"enabled,omitempty"`
|
|
|
|
Branch string `json:"branch,omitempty"`
|
|
|
|
}{
|
|
|
|
Enabled: true,
|
|
|
|
Branch: "stable",
|
|
|
|
},
|
|
|
|
},
|
2016-12-15 11:10:09 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2017-05-20 14:46:29 +02:00
|
|
|
nodes.AddNode(&Node{
|
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "0xdeadbeef0x",
|
|
|
|
VPN: true,
|
2016-12-15 11:10:09 +01:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "Xeon Multi-Core",
|
|
|
|
},
|
2017-11-21 15:12:06 +01:00
|
|
|
System: data.System{
|
2018-01-17 20:20:35 +01:00
|
|
|
SiteCode: TEST_SITE,
|
|
|
|
DomainCode: TEST_DOMAIN,
|
2017-11-21 15:12:06 +01:00
|
|
|
},
|
2016-12-15 11:10:09 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|