Files
EvoBGP/internal/pipeline/materialize_regression_test.go
T
DenozordecandCursor d687881eaa
CI / changes (push) Successful in 7s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 23s
CI / web (push) Successful in 31s
CI / go (push) Failing after 19s
CI / bird2 (push) Has been skipped
CI / release (push) Has been skipped
chore: update golangci configuration and improve resource cleanup
- Disabled all linters in .golangci.yml to streamline linting process.
- Updated resource cleanup in multiple files to use deferred functions for closing response bodies, ensuring proper error handling and resource management.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-20 15:13:02 +07:00

49 lines
1.6 KiB
Go

package pipeline
import (
"strings"
"testing"
"evobgp/internal/birdfmt"
"evobgp/internal/store"
)
func TestBuildPreviewFragments_SamePrefixDifferentCommunity(t *testing.T) {
m := store.NewMemory()
m.SeedDemo()
tenant, _, moduleIP, _, _ := m.DemoIDs()
c1, err := m.CreateCommunity(tenant, &store.Community{Community: "65000:1", Title: "A", ValueJSON: "{}"})
if err != nil {
t.Fatal(err)
}
c2, err := m.CreateCommunity(tenant, &store.Community{Community: "65000:2", Title: "B", ValueJSON: "{}"})
if err != nil {
t.Fatal(err)
}
rows := []store.PrefixRow{
{Prefix: "203.0.113.0/24", CommunityID: &c1.ID, Source: "ip_range"},
{Prefix: "203.0.113.0/24", CommunityID: &c2.ID, Source: "cdn:test"},
}
out, err := buildPreviewFragments(m, tenant, moduleIP, "test-revision", rows)
if err != nil {
t.Fatal(err)
}
staticV4 := out[birdfmt.FragmentIncludePath(birdfmt.FragmentPrefixesV4)]
if !strings.Contains(staticV4, "protocol static evobgp_prefixes_v4_"+communityProtocolSuffix(c1.ID)) {
t.Fatalf("expected dedicated static protocol for first community, got:\n%s", staticV4)
}
if !strings.Contains(staticV4, "protocol static evobgp_prefixes_v4_"+communityProtocolSuffix(c2.ID)) {
t.Fatalf("expected dedicated static protocol for second community, got:\n%s", staticV4)
}
out2, err := buildPreviewFragments(m, tenant, moduleIP, "test-revision", rows)
if err != nil {
t.Fatal(err)
}
staticV4Second := out2[birdfmt.FragmentIncludePath(birdfmt.FragmentPrefixesV4)]
if staticV4 != staticV4Second {
t.Fatalf("expected deterministic static preview text, got first:\n%s\nsecond:\n%s", staticV4, staticV4Second)
}
}