blob: 2c0fe5775ea21e52040e325738e28e8c199dc93f [file] [log] [blame]
package provider
import (
"testing"
pb "code.hackerspace.pl/hscloud/bgpwtf/cccampix/proto"
"github.com/go-test/deep"
)
func TestParseImportExport(t *testing.T) {
tests := []struct {
ut string
want *pb.IRRAttribute_ImportExport
}{
{
ut: `
from AS10674 209.251.128.177 at 216.155.103.20 action pref = 1;
accept ANY AND NOT AS-ACCELERATION-CUST
`,
want: &pb.IRRAttribute_ImportExport{
Expressions: []*pb.IRRAttribute_ImportExport_Expression{
{
Peering: "AS10674",
RouterUs: "216.155.103.20",
RouterThem: "209.251.128.177",
Actions: []string{"pref = 1"},
},
},
Filter: "ANY AND NOT AS-ACCELERATION-CUST",
},
},
{
ut: `
to AS201054 94.246.185.174 at 94.246.185.175 announce AS-BGPWTF
`,
want: &pb.IRRAttribute_ImportExport{
Expressions: []*pb.IRRAttribute_ImportExport_Expression{
{
Peering: "AS201054",
RouterUs: "94.246.185.175",
RouterThem: "94.246.185.174",
Actions: []string{},
},
},
Filter: "AS-BGPWTF",
},
},
{
// Invalid - unterminated action.
ut: `
to AS201054 94.246.185.174 at 94.246.185.175 action foo = bar
accept ANY AND NOT AS-ACCELERATION-CUST
`,
want: nil,
},
}
for _, test := range tests {
res := parseImportExport(test.ut)
if diff := deep.Equal(test.want, res); diff != nil {
t.Error(diff)
}
}
}