Skip to content

Commit b667cf1

Browse files
committed
test(netfault): lock down Opts provider matrix; document Opts breaking change
- TestOptsProviderMatrix asserts which provider interfaces each of the six Opts types implements. Accidentally adding (or removing) one of ip/tc/iptables on the wrong type now fails this test instead of silently switching code paths in generateAndRunCommands. - Remove the now-redundant TestTcpResetOpts_ImplementsOnlyIptables (the TcpReset case is covered by the matrix). - CHANGELOG: also document the Opts interface breaking change — methods ipCommands/tcCommands are no longer required, and external code that consumed them needs a type assertion.
1 parent e72cc46 commit b667cf1

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

go/action_kit_commons/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
after revert in that case.
1212
- **Breaking:** `netfault.Apply` now returns `([]string, error)` — the
1313
string slice contains preflight warnings to surface to the user.
14+
- **Breaking:** The `Opts` interface no longer requires `ipCommands` or
15+
`tcCommands`. Subsystem behavior is now opt-in via two new optional
16+
interfaces: `tcCommandProvider` (`tcCommands` + `tcRootQdiscInterfaces`)
17+
and `ipCommandProvider` (`ipCommands`), mirroring the existing
18+
`iptablesScriptProvider`. External `Opts` implementations that returned
19+
`nil, nil` from these methods can simply remove them; external callers
20+
that consumed those methods need a type assertion first.
1421

1522
## 1.6.1
1623

go/action_kit_commons/network/netfault/netfault_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,38 @@ qdisc cake 8001: dev eth1 root refcnt 2 bandwidth 1Gbit`,
104104
}
105105
}
106106

107+
// TestOptsProviderMatrix locks down which subsystem providers each Opts type
108+
// implements. Generated commands flow through type assertions in
109+
// generateAndRunCommands, so accidentally adding tcCommands to BlackholeOpts
110+
// (or any similar mistake) would silently start hitting a different code
111+
// path without any other test failing.
112+
func TestOptsProviderMatrix(t *testing.T) {
113+
cases := []struct {
114+
name string
115+
opts Opts
116+
hasIp bool
117+
hasTc bool
118+
hasIptables bool
119+
}{
120+
{"BlackholeOpts", &BlackholeOpts{}, true, false, false},
121+
{"DelayOpts", &DelayOpts{}, false, true, true},
122+
{"PackageLossOpts", &PackageLossOpts{}, false, true, false},
123+
{"CorruptPackagesOpts", &CorruptPackagesOpts{}, false, true, false},
124+
{"LimitBandwidthOpts", &LimitBandwidthOpts{}, false, true, false},
125+
{"TcpResetOpts", &TcpResetOpts{}, false, false, true},
126+
}
127+
for _, tc := range cases {
128+
t.Run(tc.name, func(t *testing.T) {
129+
_, isIp := tc.opts.(ipCommandProvider)
130+
_, isTc := tc.opts.(tcCommandProvider)
131+
_, isIptables := tc.opts.(iptablesScriptProvider)
132+
assert.Equal(t, tc.hasIp, isIp, "ipCommandProvider")
133+
assert.Equal(t, tc.hasTc, isTc, "tcCommandProvider")
134+
assert.Equal(t, tc.hasIptables, isIptables, "iptablesScriptProvider")
135+
})
136+
}
137+
}
138+
107139
func TestDelayOpts_IptablesScripts_FilterByFamily(t *testing.T) {
108140
opts := &DelayOpts{
109141
Filter: Filter{

go/action_kit_commons/network/netfault/tcp_reset_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,6 @@ func TestTcpResetOpts_chainName(t *testing.T) {
458458
(&TcpResetOpts{}).rstFilterChainName())
459459
}
460460

461-
func TestTcpResetOpts_ImplementsOnlyIptables(t *testing.T) {
462-
var opts Opts = &TcpResetOpts{}
463-
_, isIp := opts.(ipCommandProvider)
464-
assert.False(t, isIp, "TcpResetOpts must not implement ipCommandProvider")
465-
_, isTc := opts.(tcCommandProvider)
466-
assert.False(t, isTc, "TcpResetOpts must not implement tcCommandProvider")
467-
_, isIptables := opts.(iptablesScriptProvider)
468-
assert.True(t, isIptables, "TcpResetOpts must implement iptablesScriptProvider")
469-
}
470-
471461
func TestTcpResetOpts_doesConflictWith(t *testing.T) {
472462
filter := Filter{Include: network.NewNetWithPortRanges(network.NetAny, network.PortRangeAny)}
473463

0 commit comments

Comments
 (0)