Sergiusz Bazanski | 6eaaaf9 | 2019-08-02 01:25:31 +0200 | [diff] [blame] | 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | pb "code.hackerspace.pl/hscloud/bgpwtf/cccampix/proto" |
| 7 | "github.com/go-test/deep" |
| 8 | ) |
| 9 | |
| 10 | func TestParseImportExport(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | ut string |
| 13 | want *pb.IRRAttribute_ImportExport |
| 14 | }{ |
| 15 | { |
| 16 | ut: ` |
| 17 | from AS10674 209.251.128.177 at 216.155.103.20 action pref = 1; |
| 18 | accept ANY AND NOT AS-ACCELERATION-CUST |
| 19 | `, |
| 20 | want: &pb.IRRAttribute_ImportExport{ |
| 21 | Expressions: []*pb.IRRAttribute_ImportExport_Expression{ |
| 22 | { |
| 23 | Peering: "AS10674", |
| 24 | RouterUs: "216.155.103.20", |
| 25 | RouterThem: "209.251.128.177", |
| 26 | Actions: []string{"pref = 1"}, |
| 27 | }, |
| 28 | }, |
| 29 | Filter: "ANY AND NOT AS-ACCELERATION-CUST", |
| 30 | }, |
| 31 | }, |
| 32 | { |
| 33 | ut: ` |
| 34 | to AS201054 94.246.185.174 at 94.246.185.175 announce AS-BGPWTF |
| 35 | `, |
| 36 | want: &pb.IRRAttribute_ImportExport{ |
| 37 | Expressions: []*pb.IRRAttribute_ImportExport_Expression{ |
| 38 | { |
| 39 | Peering: "AS201054", |
| 40 | RouterUs: "94.246.185.175", |
| 41 | RouterThem: "94.246.185.174", |
| 42 | Actions: []string{}, |
| 43 | }, |
| 44 | }, |
| 45 | Filter: "AS-BGPWTF", |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | // Invalid - unterminated action. |
| 50 | ut: ` |
| 51 | to AS201054 94.246.185.174 at 94.246.185.175 action foo = bar |
| 52 | accept ANY AND NOT AS-ACCELERATION-CUST |
| 53 | `, |
| 54 | want: nil, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, test := range tests { |
| 59 | res := parseImportExport(test.ut) |
| 60 | if diff := deep.Equal(test.want, res); diff != nil { |
| 61 | t.Error(diff) |
| 62 | } |
| 63 | } |
| 64 | } |