Skip to content

Commit ddde740

Browse files
authored
Merge pull request #358 from sdcio/fixentrytest
fix entry tests
2 parents 6c901c1 + 6875304 commit ddde740

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

pkg/tree/entry_test.go

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,44 +1761,47 @@ func Test_Validation_MultiKey_Pattern(t *testing.T) {
17611761

17621762
// First static route: /ipv6/static-route[owner=owner-up][ipv6-prefix=prefix-default][next-hop=nexthop-gateway]/bfd-enabled
17631763
u1 := types.NewUpdate(
1764-
&sdcpb.Path{Elem: []*sdcpb.PathElem{
1765-
sdcpb.NewPathElem("ipv6", nil),
1766-
sdcpb.NewPathElem("static-route", map[string]string{
1767-
"owner": "owner-up", // Should match owner pattern 'owner-.*'
1768-
"ipv6-prefix": "prefix-default", // Should match ipv6-prefix pattern 'prefix-.*'
1769-
"next-hop": "nexthop-gateway", // Should match next-hop pattern 'nexthop-.*'
1770-
}),
1771-
sdcpb.NewPathElem("bfd-enabled", nil),
1772-
}},
1764+
nil,
17731765
bfdEnabledVal,
17741766
prio50,
17751767
owner1,
17761768
ts1,
17771769
)
17781770

1779-
_, err = root.AddUpdateRecursive(ctx, u1.Path(), u1, flagsNew)
1771+
path := &sdcpb.Path{Elem: []*sdcpb.PathElem{
1772+
sdcpb.NewPathElem("ipv6", nil),
1773+
sdcpb.NewPathElem("static-route", map[string]string{
1774+
"owner": "owner-up", // Should match owner pattern 'owner-.*'
1775+
"ipv6-prefix": "prefix-default", // Should match ipv6-prefix pattern 'prefix-.*'
1776+
"next-hop": "nexthop-gateway", // Should match next-hop pattern 'nexthop-.*'
1777+
}),
1778+
sdcpb.NewPathElem("bfd-enabled", nil),
1779+
}}
1780+
1781+
_, err = root.AddUpdateRecursive(ctx, path, u1, flagsNew)
17801782
if err != nil {
17811783
t.Fatal(err)
17821784
}
17831785

1786+
path = &sdcpb.Path{Elem: []*sdcpb.PathElem{
1787+
sdcpb.NewPathElem("ipv6", nil),
1788+
sdcpb.NewPathElem("static-route", map[string]string{
1789+
"owner": "owner-up", // Same owner and prefix
1790+
"ipv6-prefix": "prefix-default",
1791+
"next-hop": "nexthop-backup", // Different next-hop
1792+
}),
1793+
sdcpb.NewPathElem("bfd-enabled", nil),
1794+
}}
17841795
// Second static route: /ipv6/static-route[owner=owner-up][ipv6-prefix=prefix-default][next-hop=nexthop-backup]/bfd-enabled
17851796
u2 := types.NewUpdate(
1786-
&sdcpb.Path{Elem: []*sdcpb.PathElem{
1787-
sdcpb.NewPathElem("ipv6", nil),
1788-
sdcpb.NewPathElem("static-route", map[string]string{
1789-
"owner": "owner-up", // Same owner and prefix
1790-
"ipv6-prefix": "prefix-default",
1791-
"next-hop": "nexthop-backup", // Different next-hop
1792-
}),
1793-
sdcpb.NewPathElem("bfd-enabled", nil),
1794-
}},
1797+
nil,
17951798
bfdEnabledVal,
17961799
prio50,
17971800
owner1,
17981801
ts1,
17991802
)
18001803

1801-
_, err = root.AddUpdateRecursive(ctx, u2.Path(), u2, flagsNew)
1804+
_, err = root.AddUpdateRecursive(ctx, path, u2, flagsNew)
18021805
if err != nil {
18031806
t.Fatal(err)
18041807
}
@@ -1829,18 +1832,19 @@ func Test_Validation_MultiKey_Pattern(t *testing.T) {
18291832
// Create a static-route list entry with invalid owner (doesn't match pattern)
18301833
bfdEnabledVal := &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: true}}
18311834

1835+
path := &sdcpb.Path{Elem: []*sdcpb.PathElem{
1836+
sdcpb.NewPathElem("ipv6", nil),
1837+
sdcpb.NewPathElem("static-route", map[string]string{
1838+
"owner": "invalid", // Should FAIL 'owner-.*' pattern
1839+
"ipv6-prefix": "prefix-default", // Should match 'prefix-.*' pattern
1840+
"next-hop": "nexthop-gateway", // Should match 'nexthop-.*' pattern
1841+
}),
1842+
sdcpb.NewPathElem("bfd-enabled", nil),
1843+
}}
18321844
// Path: /ipv6/static-route[owner=invalid][ipv6-prefix=prefix-default][next-hop=nexthop-gateway]/bfd-enabled
18331845
// owner="invalid" should FAIL 'owner-.*' pattern (doesn't start with 'owner-')
18341846
u1 := types.NewUpdate(
1835-
&sdcpb.Path{Elem: []*sdcpb.PathElem{
1836-
sdcpb.NewPathElem("ipv6", nil),
1837-
sdcpb.NewPathElem("static-route", map[string]string{
1838-
"owner": "invalid", // Should FAIL 'owner-.*' pattern
1839-
"ipv6-prefix": "prefix-default", // Should match 'prefix-.*' pattern
1840-
"next-hop": "nexthop-gateway", // Should match 'nexthop-.*' pattern
1841-
}),
1842-
sdcpb.NewPathElem("bfd-enabled", nil),
1843-
}},
1847+
nil,
18441848
bfdEnabledVal,
18451849
prio50,
18461850
owner1,
@@ -1849,7 +1853,7 @@ func Test_Validation_MultiKey_Pattern(t *testing.T) {
18491853

18501854
// Pattern validation happens during AddUpdateRecursive (in checkAndCreateKeysAsLeafs)
18511855
// so we expect an error here
1852-
_, err = root.AddUpdateRecursive(ctx, u1.Path(), u1, flagsNew)
1856+
_, err = root.AddUpdateRecursive(ctx, path, u1, flagsNew)
18531857
if err == nil {
18541858
t.Fatal("expected error for owner pattern mismatch, but got none")
18551859
}
@@ -1872,18 +1876,20 @@ func Test_Validation_MultiKey_Pattern(t *testing.T) {
18721876
// Create a static-route list entry with invalid next-hop (doesn't match pattern)
18731877
bfdEnabledVal := &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: true}}
18741878

1879+
path := &sdcpb.Path{Elem: []*sdcpb.PathElem{
1880+
sdcpb.NewPathElem("ipv6", nil),
1881+
sdcpb.NewPathElem("static-route", map[string]string{
1882+
"owner": "owner-up", // Should match 'owner-.*' pattern
1883+
"ipv6-prefix": "prefix-default", // Should match 'prefix-.*' pattern
1884+
"next-hop": "invalid", // Should FAIL 'nexthop-.*' pattern
1885+
}),
1886+
sdcpb.NewPathElem("bfd-enabled", nil),
1887+
}}
1888+
18751889
// Path: /ipv6/static-route[owner=owner-up][ipv6-prefix=prefix-default][next-hop=invalid]/bfd-enabled
18761890
// next-hop="invalid" should FAIL 'nexthop-.*' pattern (doesn't start with 'nexthop-')
18771891
u1 := types.NewUpdate(
1878-
&sdcpb.Path{Elem: []*sdcpb.PathElem{
1879-
sdcpb.NewPathElem("ipv6", nil),
1880-
sdcpb.NewPathElem("static-route", map[string]string{
1881-
"owner": "owner-up", // Should match 'owner-.*' pattern
1882-
"ipv6-prefix": "prefix-default", // Should match 'prefix-.*' pattern
1883-
"next-hop": "invalid", // Should FAIL 'nexthop-.*' pattern
1884-
}),
1885-
sdcpb.NewPathElem("bfd-enabled", nil),
1886-
}},
1892+
nil,
18871893
bfdEnabledVal,
18881894
prio50,
18891895
owner1,
@@ -1892,7 +1898,7 @@ func Test_Validation_MultiKey_Pattern(t *testing.T) {
18921898

18931899
// Pattern validation happens during AddUpdateRecursive (in checkAndCreateKeysAsLeafs)
18941900
// so we expect an error here
1895-
_, err = root.AddUpdateRecursive(ctx, u1.Path(), u1, flagsNew)
1901+
_, err = root.AddUpdateRecursive(ctx, path, u1, flagsNew)
18961902
if err == nil {
18971903
t.Fatal("expected error for next-hop pattern mismatch, but got none")
18981904
}

0 commit comments

Comments
 (0)