2016-03-19 14:07:44 +00:00
|
|
|
package respond
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/respond-collector/data"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParse(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2016-03-19 22:18:26 +00:00
|
|
|
var decompressed *data.ResponseData
|
2016-03-19 14:07:44 +00:00
|
|
|
|
|
|
|
// callback function
|
2016-03-19 22:18:26 +00:00
|
|
|
onReceive := func(addr net.UDPAddr, res *data.ResponseData) {
|
|
|
|
decompressed = res
|
2016-03-19 14:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
collector := &Collector{
|
|
|
|
msgType: reflect.TypeOf(data.NodeInfo{}),
|
|
|
|
onReceive: onReceive,
|
|
|
|
}
|
|
|
|
|
|
|
|
// read testdata
|
|
|
|
compressed, err := ioutil.ReadFile("testdata/nodeinfo.flated")
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
collector.parse(&Response{
|
|
|
|
Raw: compressed,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NotNil(decompressed)
|
2016-03-19 22:18:26 +00:00
|
|
|
assert.NotNil(decompressed.NodeInfo)
|
|
|
|
assert.Equal("f81a67a5e9c1", decompressed.NodeInfo.NodeId)
|
2016-03-19 14:07:44 +00:00
|
|
|
}
|