Increase test coverage
This commit is contained in:
parent
5c2a655b11
commit
2068d2b1a1
2
main.go
2
main.go
@ -46,6 +46,8 @@ func main() {
|
||||
}
|
||||
|
||||
nodes = models.NewNodes(config)
|
||||
nodes.Start()
|
||||
|
||||
if config.Respondd.Enable {
|
||||
collectInterval := time.Second * time.Duration(config.Respondd.CollectInterval)
|
||||
collector = respond.NewCollector(db, nodes, collectInterval, config.Respondd.Interface)
|
||||
|
@ -39,12 +39,15 @@ func NewNodes(config *Config) *Nodes {
|
||||
if config.Nodes.NodesPath != "" {
|
||||
nodes.load()
|
||||
}
|
||||
go nodes.worker()
|
||||
|
||||
nodes.Version = 2
|
||||
return nodes
|
||||
}
|
||||
|
||||
func (nodes *Nodes) Start() {
|
||||
go nodes.worker()
|
||||
}
|
||||
|
||||
// Update a Node
|
||||
func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
|
||||
now := jsontime.Now()
|
||||
@ -95,8 +98,8 @@ func (nodes *Nodes) GetNodesMini() *meshviewer.Nodes {
|
||||
List: make(map[string]*meshviewer.Node),
|
||||
Timestamp: nodes.Timestamp,
|
||||
}
|
||||
for nodeID := range nodes.List {
|
||||
|
||||
for nodeID := range nodes.List {
|
||||
node, _ := meshviewerNodes.List[nodeID]
|
||||
nodeOrigin := nodes.List[nodeID]
|
||||
if node == nil {
|
||||
|
@ -49,7 +49,7 @@ func TestLoadAndSave(t *testing.T) {
|
||||
config := &Config{}
|
||||
config.Nodes.NodesPath = "testdata/nodes.json"
|
||||
|
||||
nodes := &Nodes{config: config}
|
||||
nodes := NewNodes(config)
|
||||
nodes.load()
|
||||
|
||||
tmpfile, _ := ioutil.TempFile("/tmp", "nodes")
|
||||
@ -73,3 +73,29 @@ func TestUpdateNodes(t *testing.T) {
|
||||
|
||||
assert.Equal(1, len(nodes.List))
|
||||
}
|
||||
|
||||
func TestGlobalStats(t *testing.T) {
|
||||
stats := createTestNodes().GlobalStats()
|
||||
|
||||
assert := assert.New(t)
|
||||
assert.EqualValues(uint32(1), stats.Nodes)
|
||||
assert.EqualValues(uint32(23), stats.Clients)
|
||||
}
|
||||
|
||||
func TestNodesMini(t *testing.T) {
|
||||
mini := createTestNodes().GetNodesMini()
|
||||
|
||||
assert := assert.New(t)
|
||||
assert.Equal(1, len(mini.List))
|
||||
}
|
||||
|
||||
func createTestNodes() *Nodes {
|
||||
nodes := NewNodes(&Config{})
|
||||
|
||||
res := &data.ResponseData{
|
||||
Statistics: &data.Statistics{},
|
||||
}
|
||||
res.Statistics.Clients.Total = 23
|
||||
nodes.Update("abcdef012345", res)
|
||||
return nodes
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user