1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

added test for routes parsing

This commit is contained in:
Matthias Hannig 2017-06-22 15:38:18 +02:00
parent 92dc24e764
commit b96a864b04

View file

@ -1,10 +1,16 @@
package bird
import (
"io/ioutil"
"reflect"
"testing"
)
func readSampleData(filename string) ([]byte, error) {
sample := "../test/" + filename
return ioutil.ReadFile(sample)
}
func TestParseBgpRoutes(t *testing.T) {
inputs := []string{
@ -33,3 +39,29 @@ func TestParseBgpRoutes(t *testing.T) {
}
}
func TestParseRoutesAll(t *testing.T) {
sample, err := readSampleData("routes_all.sample")
if err != nil {
t.Error(err)
}
// Parse routes
result := parseRoutes(sample)
routes, ok := result["routes"].([]Parsed)
if !ok {
t.Error("Error getting routes")
}
if len(routes) != 4 {
t.Error("Expected number of routes to be 3")
}
expectedNetworks := []string{"16.0.0.0/24", "200.0.0.0/24", "200.0.0.0/24", "16.0.0.0/24"}
for i, route := range routes {
net := route["network"].(string)
if net != expectedNetworks[i] {
t.Error("Expected network to be:", expectedNetworks[i], "not", net)
}
}
}