46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package birdfmt
|
|
|
|
import (
|
|
_ "embed"
|
|
"net/netip"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
//go:embed testdata/golden/static_ipv4_small.golden
|
|
var goldenStaticIPv4Small string
|
|
|
|
func TestRenderStaticIPv4Protocol_Golden(t *testing.T) {
|
|
p1 := netip.MustParsePrefix("203.0.113.0/24")
|
|
p2 := netip.MustParsePrefix("198.51.100.0/24")
|
|
// duplicate to assert dedup
|
|
got := RenderStaticIPv4Protocol("evobgp_test", []netip.Prefix{p1, p2, p1})
|
|
|
|
want := strings.TrimSuffix(goldenStaticIPv4Small, "\n")
|
|
got = strings.TrimSuffix(got, "\n")
|
|
if got != want {
|
|
t.Fatalf("golden mismatch\n--- got ---\n%s\n--- want ---\n%s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderStaticIPv4Protocol_Empty(t *testing.T) {
|
|
got := RenderStaticIPv4Protocol("evobgp_empty", nil)
|
|
if !strings.Contains(got, "protocol static evobgp_empty") {
|
|
t.Fatal(got)
|
|
}
|
|
if !strings.Contains(got, "ipv4") {
|
|
t.Fatal(got)
|
|
}
|
|
}
|
|
|
|
func TestRenderStaticIPv6Protocol_Dedup(t *testing.T) {
|
|
p := netip.MustParsePrefix("2001:db8::/32")
|
|
got := RenderStaticIPv6Protocol("evobgp_v6", []netip.Prefix{p, p})
|
|
if !strings.Contains(got, "2001:db8::/32") {
|
|
t.Fatal(got)
|
|
}
|
|
if !strings.Contains(got, "ipv6") {
|
|
t.Fatal(got)
|
|
}
|
|
}
|