56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package birdfmt
|
|
|
|
import (
|
|
_ "embed"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
//go:embed testdata/golden/main_bird_skeleton.golden
|
|
var goldenMainBirdSkeleton string
|
|
|
|
func TestRenderMainBirdConf_Golden(t *testing.T) {
|
|
got, err := RenderMainBirdConf(MainBirdConfOptions{
|
|
RouterID: "192.0.2.1",
|
|
Includes: StandardIncludeFragments(),
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := strings.TrimSuffix(goldenMainBirdSkeleton, "\n")
|
|
got = strings.TrimSuffix(got, "\n")
|
|
if got != want {
|
|
t.Fatalf("golden mismatch\n--- got ---\n%s\n--- want ---\n%s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestRenderMainBirdConf_Preamble(t *testing.T) {
|
|
got, err := RenderMainBirdConf(MainBirdConfOptions{
|
|
RouterID: "192.0.2.1",
|
|
Includes: nil,
|
|
Preamble: "operator note\n# already commented",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.HasPrefix(got, "# operator note\n") {
|
|
t.Fatalf("expected preamble prefix, got:\n%s", got)
|
|
}
|
|
if !strings.Contains(got, "# already commented") {
|
|
t.Fatal(got)
|
|
}
|
|
}
|
|
|
|
func TestRenderMainBirdConf_Errors(t *testing.T) {
|
|
_, err := RenderMainBirdConf(MainBirdConfOptions{})
|
|
if err == nil {
|
|
t.Fatal("expected error for empty router id")
|
|
}
|
|
}
|
|
|
|
func TestFragmentIncludePath(t *testing.T) {
|
|
if p := FragmentIncludePath(FragmentPrefixesV4); p != "bird.d/evobgp_prefixes_v4.conf" {
|
|
t.Fatal(p)
|
|
}
|
|
}
|