yanic/respond/collector_test.go

39 lines
747 B
Go
Raw Normal View History

2016-03-19 15:07:44 +01: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 23:18:26 +01:00
var decompressed *data.ResponseData
2016-03-19 15:07:44 +01:00
// callback function
2016-03-19 23:18:26 +01:00
onReceive := func(addr net.UDPAddr, res *data.ResponseData) {
decompressed = res
2016-03-19 15:07:44 +01: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 23:18:26 +01:00
assert.NotNil(decompressed.NodeInfo)
assert.Equal("f81a67a5e9c1", decompressed.NodeInfo.NodeId)
2016-03-19 15:07:44 +01:00
}