1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00
alice-lg-alice-lg/backend/bgp_communities_test.go
2018-09-07 10:24:51 +02:00

85 lines
1.5 KiB
Go

package main
import (
"testing"
)
func TestCommunityLookup(t *testing.T) {
c := MakeWellKnownBgpCommunities()
label, err := c.Lookup("65535:666")
if err != nil {
t.Error(err)
}
if label != "blackhole" {
t.Error("Label should have been: blackhole, got:", label)
}
// Okay now try some fails
label, err = c.Lookup("65535")
if err == nil {
t.Error("Expected error!")
}
label, err = c.Lookup("65535:23:42")
if err == nil {
t.Error("Expected not found error!")
}
}
func TestSetCommunity(t *testing.T) {
c := MakeWellKnownBgpCommunities()
c.Set("2342:10", "foo")
c.Set("2342:42:23", "bar")
// Simple lookup
label, err := c.Lookup("2342:10")
if err != nil {
t.Error(err)
}
if label != "foo" {
t.Error("Expected foo for 2342:10, got:", label)
}
label, err = c.Lookup("2342:42:23")
if err != nil {
t.Error(err)
}
if label != "bar" {
t.Error("Expected bar for 2342:42:23, got:", label)
}
}
func TestWildcardLookup(t *testing.T) {
c := MakeWellKnownBgpCommunities()
c.Set("2342:*", "foobar $0")
c.Set("42:*:1", "baz")
// This should work
label, err := c.Lookup("2342:23")
if err != nil {
t.Error(err)
}
if label != "foobar $0" {
t.Error("Did not get expected label.")
}
// This however not
label, err = c.Lookup("2342:23:666")
if err == nil {
t.Error("Lookup should have failed, got label:", label)
}
// This should again work
label, err = c.Lookup("42:123:1")
if err != nil {
t.Error(err)
}
if label != "baz" {
t.Error("Unexpected label for key")
}
}