2016-03-20 17:30:44 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2016-03-21 11:26:08 +00:00
|
|
|
"github.com/FreifunkBremen/respond-collector/data"
|
2016-03-20 17:30:44 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadAndSave(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
config := &Config{}
|
|
|
|
config.Nodes.NodesPath = "testdata/nodes.json"
|
|
|
|
|
|
|
|
nodes := &Nodes{config: config}
|
|
|
|
nodes.load()
|
|
|
|
|
|
|
|
tmpfile, _ := ioutil.TempFile("/tmp", "nodes")
|
|
|
|
save(nodes, tmpfile.Name())
|
|
|
|
os.Remove(tmpfile.Name())
|
|
|
|
|
|
|
|
assert.Equal(1, len(nodes.List))
|
|
|
|
}
|
2016-03-21 11:26:08 +00:00
|
|
|
|
|
|
|
func TestUpdateNodes(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
nodes := &Nodes{List: make(map[string]*Node)}
|
|
|
|
assert.Equal(0, len(nodes.List))
|
|
|
|
|
|
|
|
res := &data.ResponseData{
|
|
|
|
Neighbours: &data.Neighbours{},
|
|
|
|
Statistics: &data.Statistics{},
|
|
|
|
NodeInfo: &data.NodeInfo{},
|
|
|
|
}
|
|
|
|
nodes.Update("abcdef012345", res)
|
|
|
|
|
|
|
|
assert.Equal(1, len(nodes.List))
|
|
|
|
}
|