package dynamicrouting import ( "strings" "testing" "time" ) 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 } func TestParseBirdSinceToUptime(t *testing.T) { refTime := time.Date(2026, 11, 2, 12, 0, 0, 0, time.Local) tests := []struct { name string input string expected string }{ { name: "ISO long same day", input: "2026-11-02 10:06:15", expected: "01h 53m 45s", }, { name: "ISO long with milliseconds", input: "2026-11-02 10:06:15.123", expected: "01h 53m 44s", }, { name: "ISO long previous day", input: "2026-10-31 13:15:43", expected: "1d 22h 44m 17s", }, { name: "Date only", input: "2026-10-31", expected: "2d 12h 00m 00s", }, { name: "Time only with ms", input: "10:06:15.631", expected: "01h 53m 45s", }, { name: "Empty", input: "", expected: "", }, { name: "Invalid", input: "not-a-date", expected: "", }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { got := parseBirdSinceToUptime(tc.input, refTime) if got != tc.expected { t.Errorf("%s: got %q, want %q", tc.name, got, tc.expected) } }) } }