| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package dynamicrouting
- import (
- "strings"
- "testing"
- )
- func TestBGPConfigGeneration(t *testing.T) {
- m := &Manager{}
- m.config.BGPInstance = BGPInstance{
- Enabled: true,
- AS: 65001,
- RouterID: "192.168.131.56",
- RedistributeStatic: true,
- }
- m.config.BGPNetworks = []BGPNetwork{
- {
- ID: "net-1",
- Network: "192.168.100.0/24",
- Disabled: false,
- },
- }
- m.config.BGPPeers = []BGPPeer{
- {
- ID: "peer-1",
- Name: "TestPeer",
- RemoteAddress: "192.168.129.225",
- RemoteAS: 65555,
- Passive: true,
- NexthopSelf: true,
- RedistStatic: true,
- OutputNetworks: []string{"192.168.200.0/24"},
- },
- }
- // Mock bird and birdc
- dir := t.TempDir()
- t.Setenv("PATH", dir+":"+dir)
- // Test configuration generation
- sb := &strings.Builder{}
- // Test the export filter logic directly
- exportSources := []string{`source = RTS_BGP`}
- if m.config.BGPPeers[0].RedistStatic || m.config.BGPInstance.RedistributeStatic {
- exportSources = append(exportSources, `source ~ [ RTS_STATIC, RTS_INHERIT ]`)
- }
- exportRule := strings.Join(exportSources, ") || (")
- if !strings.Contains(exportRule, "RTS_INHERIT") {
- t.Fatalf("Expected exportRule to contain RTS_INHERIT for kernel static routes, got %s", exportRule)
- }
- _ = sb
- }
|