Skip to content

Commit 5d945ac

Browse files
committed
chore(test): relocate bridge-as-gateway no-longer-fails pin to multidoc test file
TestContract_Errors_MultidocBridgeAsGateway_NoLongerFails lived in contract_errors_test.go but stopped pinning an error contract once BridgeConfig emission landed — it now asserts a clean render. A future reader landing in contract_errors_test.go on the name prefix would expect a fail-test and find an assert-clean-render test instead. Move the function next to TestContract_NetworkMultidoc_BridgeConfigEmitted in contract_network_multidoc_test.go so the file location matches the contract being pinned, and rename it to TestContract_NetworkMultidoc_BridgeAsGateway_NoLongerFails to fit the surrounding naming convention. The bridgeAsGatewayLookup fixture moves alongside its sole consumer; no other test in the package references it. Section header `=== Bridge as gateway: no longer fails ===` added in the new location to match the file's existing indexing style (`=== Section ===` markers used throughout). Catalogue header in contract_errors_test.go renumbered: item 4 dropped, items 5/6 renumbered to 4/5, with a one-line pointer to the new home of the bridge-as-gateway pin so a reader who indexes the file by that catalogue is led to the right place. Pure relocation + comment cleanup; test logic and assertions unchanged. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 6e914ea commit 5d945ac

2 files changed

Lines changed: 101 additions & 93 deletions

File tree

‎pkg/engine/contract_errors_test.go‎

Lines changed: 8 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
// 1. endpoint missing → `required` guard
2525
// 2. advertisedSubnets empty + no discovery default route → `fail`
2626
// 3. multi-doc + existing legacy machine.network.interfaces[] → `fail`
27-
// 4. multi-doc + bridge as IPv4-default link → `fail`
28-
// 5. multi-doc + VLAN with unresolvable parent → `fail`
29-
// 6. multi-doc + VLAN with no vlanID → `fail`
27+
// 4. multi-doc + VLAN with unresolvable parent → `fail`
28+
// 5. multi-doc + VLAN with no vlanID → `fail`
29+
//
30+
// The bridge-as-gateway case used to be item 4 in this catalogue
31+
// when it was a hard-fail; after BridgeConfig emission landed it
32+
// no longer fails, and its negative pin lives in
33+
// contract_network_multidoc_test.go alongside the related
34+
// BridgeConfigEmitted contract.
3035

3136
package engine
3237

@@ -205,96 +210,6 @@ func TestContract_Errors_MultidocLegacyInterfacesBlock(t *testing.T) {
205210
}
206211
}
207212

208-
// === fail: multi-doc + bridge as IPv4-default link ===
209-
210-
// bridgeAsGatewayLookup builds a LookupFunc emulating a bridge link
211-
// carrying the IPv4 default route. Triggers the multi-doc renderer's
212-
// "bridge as gateway" hard-fail.
213-
func bridgeAsGatewayLookup() func(string, string, string) (map[string]any, error) {
214-
br0 := map[string]any{
215-
"metadata": map[string]any{"id": "br0"},
216-
"spec": map[string]any{
217-
"kind": "bridge",
218-
"index": 5,
219-
// busPath intentionally absent: bridges aren't physical NICs.
220-
// configurable_link_names accepts them via the $isVirtual branch.
221-
},
222-
}
223-
links := map[string]any{
224-
"apiVersion": "v1",
225-
"kind": "List",
226-
"items": []any{br0},
227-
}
228-
routes := map[string]any{
229-
"apiVersion": "v1",
230-
"kind": "List",
231-
"items": []any{
232-
map[string]any{
233-
"spec": map[string]any{
234-
"dst": "",
235-
"gateway": "192.168.1.1",
236-
"outLinkName": "br0",
237-
"family": "inet4",
238-
"table": "main",
239-
},
240-
},
241-
},
242-
}
243-
addresses := map[string]any{
244-
"apiVersion": "v1",
245-
"kind": "List",
246-
"items": []any{
247-
map[string]any{
248-
"spec": map[string]any{
249-
"linkName": "br0",
250-
"address": "192.168.1.10/24",
251-
"family": "inet4",
252-
"scope": "global",
253-
},
254-
},
255-
},
256-
}
257-
return func(resource, _, id string) (map[string]any, error) {
258-
switch resource {
259-
case "links":
260-
if id == "br0" {
261-
return br0, nil
262-
}
263-
if id == "" {
264-
return links, nil
265-
}
266-
case "routes":
267-
return routes, nil
268-
case "addresses":
269-
return addresses, nil
270-
}
271-
return map[string]any{}, nil
272-
}
273-
}
274-
275-
// Contract: multi-doc renderer no longer aborts when a bridge
276-
// carries the IPv4 default route — it now emits a typed
277-
// BridgeConfig document with the gateway. The previous shape
278-
// hard-failed here on the premise that BridgeConfig emission was
279-
// unimplemented, but the typed-document branch handles bridges
280-
// symmetrically to bonds today. The per-chart cross-product is
281-
// pinned in TestContract_NetworkMultidoc_BridgeConfigEmitted and
282-
// TestMultiDocEmitsBridgeConfigWhenBridgeCarriesDefaultRoute; this
283-
// test stays as the negative pin against the previous fail-fast.
284-
func TestContract_Errors_MultidocBridgeAsGateway_NoLongerFails(t *testing.T) {
285-
for _, chartPath := range []string{cozystackChartPath, genericChartPath} {
286-
t.Run(chartPath, func(t *testing.T) {
287-
err := renderExpectingError(t, chartPath, multidocTalos, bridgeAsGatewayLookup(), map[string]any{
288-
"endpoint": testEndpoint,
289-
"advertisedSubnets": []any{testAdvertisedSubnet},
290-
})
291-
if err != nil {
292-
t.Errorf("bridge-as-gateway must no longer fail (BridgeConfig is emitted now), got: %v", err)
293-
}
294-
})
295-
}
296-
}
297-
298213
// === fail: multi-doc + VLAN with no parent ===
299214

300215
// vlanMissingParentLookup builds a LookupFunc whose VLAN link has a

‎pkg/engine/contract_network_multidoc_test.go‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,99 @@ func TestContract_NetworkMultidoc_BridgeConfigEmitted(t *testing.T) {
374374
assertContains(t, out, "name: br0")
375375
}
376376

377+
// === Bridge as gateway: no longer fails ===
378+
379+
// bridgeAsGatewayLookup builds a LookupFunc emulating a bridge link
380+
// carrying the IPv4 default route. Used to be the trigger for the
381+
// multi-doc renderer's "bridge as gateway" hard-fail before
382+
// BridgeConfig emission landed; today it produces a clean render
383+
// pinned by TestContract_NetworkMultidoc_BridgeAsGateway_NoLongerFails
384+
// below.
385+
func bridgeAsGatewayLookup() func(string, string, string) (map[string]any, error) {
386+
br0 := map[string]any{
387+
"metadata": map[string]any{"id": "br0"},
388+
"spec": map[string]any{
389+
"kind": "bridge",
390+
"index": 5,
391+
// busPath intentionally absent: bridges aren't physical NICs.
392+
// configurable_link_names accepts them via the $isVirtual branch.
393+
},
394+
}
395+
links := map[string]any{
396+
"apiVersion": "v1",
397+
"kind": "List",
398+
"items": []any{br0},
399+
}
400+
routes := map[string]any{
401+
"apiVersion": "v1",
402+
"kind": "List",
403+
"items": []any{
404+
map[string]any{
405+
"spec": map[string]any{
406+
"dst": "",
407+
"gateway": "192.168.1.1",
408+
"outLinkName": "br0",
409+
"family": "inet4",
410+
"table": "main",
411+
},
412+
},
413+
},
414+
}
415+
addresses := map[string]any{
416+
"apiVersion": "v1",
417+
"kind": "List",
418+
"items": []any{
419+
map[string]any{
420+
"spec": map[string]any{
421+
"linkName": "br0",
422+
"address": "192.168.1.10/24",
423+
"family": "inet4",
424+
"scope": "global",
425+
},
426+
},
427+
},
428+
}
429+
return func(resource, _, id string) (map[string]any, error) {
430+
switch resource {
431+
case "links":
432+
if id == "br0" {
433+
return br0, nil
434+
}
435+
if id == "" {
436+
return links, nil
437+
}
438+
case "routes":
439+
return routes, nil
440+
case "addresses":
441+
return addresses, nil
442+
}
443+
return map[string]any{}, nil
444+
}
445+
}
446+
447+
// Contract: multi-doc renderer no longer aborts when a bridge
448+
// carries the IPv4 default route — it now emits a typed
449+
// BridgeConfig document with the gateway. The previous shape
450+
// hard-failed here on the premise that BridgeConfig emission was
451+
// unimplemented, but the typed-document branch handles bridges
452+
// symmetrically to bonds today. The per-chart cross-product is
453+
// pinned in TestContract_NetworkMultidoc_BridgeConfigEmitted and
454+
// TestMultiDocEmitsBridgeConfigWhenBridgeCarriesDefaultRoute; this
455+
// test stays as the negative pin against the previous fail-fast.
456+
func TestContract_NetworkMultidoc_BridgeAsGateway_NoLongerFails(t *testing.T) {
457+
for _, chartPath := range []string{cozystackChartPath, genericChartPath} {
458+
t.Run(chartPath, func(t *testing.T) {
459+
err := renderExpectingError(t, chartPath, multidocTalos, bridgeAsGatewayLookup(), map[string]any{
460+
"endpoint": testEndpoint,
461+
"advertisedSubnets": []any{testAdvertisedSubnet},
462+
})
463+
if err != nil {
464+
t.Errorf("bridge-as-gateway must no longer fail (BridgeConfig is emitted now), got: %v", err)
465+
}
466+
})
467+
}
468+
}
469+
377470
// Contract: a controlplane floatingIP that lives inside the subnet
378471
// configured on a bridge link now legitimately lands on the bridge —
379472
// the bridge is fully rendered as a typed BridgeConfig document, so

0 commit comments

Comments
 (0)