2016-03-19 15:07:44 +01:00
|
|
|
package respond
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
2017-10-18 18:22:14 +02:00
|
|
|
"time"
|
2016-03-19 15:07:44 +01:00
|
|
|
|
2017-10-18 18:22:14 +02:00
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
2016-03-19 15:07:44 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-01-17 20:20:35 +01:00
|
|
|
const (
|
|
|
|
SITE_TEST = "ffhb"
|
|
|
|
DOMAIN_TEST = "city"
|
|
|
|
)
|
2017-11-21 15:12:06 +01:00
|
|
|
|
2017-10-18 18:22:14 +02:00
|
|
|
func TestCollector(t *testing.T) {
|
2018-01-07 21:00:56 +01:00
|
|
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
2017-10-18 18:22:14 +02:00
|
|
|
|
2018-01-17 20:20:35 +01:00
|
|
|
collector := NewCollector(nil, nodes, map[string][]string{SITE_TEST: {DOMAIN_TEST}}, []string{}, 10001)
|
2017-10-18 18:22:14 +02:00
|
|
|
collector.Start(time.Millisecond)
|
|
|
|
time.Sleep(time.Millisecond * 10)
|
|
|
|
collector.Close()
|
|
|
|
}
|
|
|
|
|
2016-03-19 15:07:44 +01:00
|
|
|
func TestParse(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
// read testdata
|
|
|
|
compressed, err := ioutil.ReadFile("testdata/nodeinfo.flated")
|
|
|
|
assert.Nil(err)
|
|
|
|
|
2016-10-03 19:55:37 +02:00
|
|
|
res := &Response{
|
2016-03-19 15:07:44 +01:00
|
|
|
Raw: compressed,
|
2016-10-03 19:55:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err := res.parse()
|
|
|
|
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NotNil(data)
|
2016-03-19 15:07:44 +01:00
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
assert.Equal("f81a67a5e9c1", data.NodeInfo.NodeID)
|
2016-03-19 15:07:44 +01:00
|
|
|
}
|