MCPcopy Create free account
hub / github.com/cozystack/talm / TestDefaultGatewayIsIPv4OnDualStack

Function TestDefaultGatewayIsIPv4OnDualStack

pkg/engine/render_test.go:1590–1610  ·  view source on GitHub ↗

TestDefaultGatewayIsIPv4OnDualStack pins that talm.discovered.default_gateway returns the IPv4 default-route gateway, not the IPv6 one, when both are present on the node. The cozystack and generic charts pair this gateway with a hardcoded IPv4 destination (`network: 0.0.0.0/0`, or no `network:` at a

(t *testing.T)

Source from the content-addressed store, hash-verified

1588// first-iterated gateway, which on real Hetzner-style dual-stack nodes
1589// is often the IPv6 entry.
1590func TestDefaultGatewayIsIPv4OnDualStack(t *testing.T) {
1591 const tmpl = `gw={{ include "talm.discovered.default_gateway" . }}
1592`
1593 chartRoot := createTestChart(t, "tc", "out.yaml", tmpl)
1594 helpersSrc, err := os.ReadFile("../../charts/talm/templates/_helpers.tpl")
1595 if err != nil {
1596 t.Fatalf("read helpers: %v", err)
1597 }
1598 if err := os.WriteFile(filepath.Join(chartRoot, "templates", "_helpers.tpl"), helpersSrc, 0o644); err != nil {
1599 t.Fatalf("write vendored helpers: %v", err)
1600 }
1601
1602 output := renderChartTemplateWithLookup(t, chartRoot, "templates/out.yaml", secondaryNicLookup())
1603
1604 if !strings.Contains(output, "gw=192.168.1.1") {
1605 t.Errorf("expected default_gateway to return IPv4 192.168.1.1, got:\n%s", output)
1606 }
1607 if strings.Contains(output, "gw=fe80::1") {
1608 t.Errorf("default_gateway returned IPv6 fe80::1; the consumer pairs this with an IPv4 destination and Talos will reject the resulting route:\n%s", output)
1609 }
1610}
1611
1612// TestDefaultLinkHelpersFollowIPv4OnTwoNicDualStack pins that every
1613// default_*_by_gateway helper (link name, MAC, busPath, deviceSelector)

Callers

nothing calls this directly

Calls 3

createTestChartFunction · 0.85
secondaryNicLookupFunction · 0.85

Tested by

no test coverage detected