Repository navigation
Add TestNftabler - #50180
Add TestNftabler#50180
Conversation
Signed-off-by: Rob Murray <[email protected]>
| // Disable undoes Enable. Intended for unit testing. | ||
| func Disable() { |
There was a problem hiding this comment.
I wish there was a way to share _test.go field between tests. I guess some if testing.Testing() would come closest to prevent it being used for other purposes, but of course would still compile the code.
Well, "meh" it's an internal package, so should not be an issue.
There was a problem hiding this comment.
I hadn't thought about test.Testing() ... could do that, but it might lead to unpleasant surprises when a test works but production code does something different?
Exporting the function seemed better than duplicating it in another _test.go, but not really ideal. As you say though, it's an internal package.
There was a problem hiding this comment.
Yeah, not worth changing; if we'd use the test.Testing() approach, we'd indeed need some error return to make it not ignored silently
There was a problem hiding this comment.
if !testing.Testing() {
panic(...)
}There was a problem hiding this comment.
Heh, yeah, I considered panic, but then thought "not worth it for an internal package".
| const ( | ||
| ipv4 int64 = iota | ||
| ipv6 | ||
| hairpin | ||
| internal | ||
| icc | ||
| masq | ||
| snat | ||
| bindLocalhost | ||
| wsl2Mirrored | ||
| numBoolParams | ||
| ) | ||
| nftables.Enable() | ||
| t.Cleanup(func() { nftables.Disable() }) // Cleanup instead of defer, this func returns before the parallel subtests finish. | ||
| for i := range 1 << numBoolParams { | ||
| p := func(n int64) bool { return (i & (1 << n)) != 0 } |
There was a problem hiding this comment.
| const ( | |
| ipv4 int64 = iota | |
| ipv6 | |
| hairpin | |
| internal | |
| icc | |
| masq | |
| snat | |
| bindLocalhost | |
| wsl2Mirrored | |
| numBoolParams | |
| ) | |
| nftables.Enable() | |
| t.Cleanup(func() { nftables.Disable() }) // Cleanup instead of defer, this func returns before the parallel subtests finish. | |
| for i := range 1 << numBoolParams { | |
| p := func(n int64) bool { return (i & (1 << n)) != 0 } | |
| const ( | |
| ipv4 int64 = 1 << iota | |
| ipv6 | |
| hairpin | |
| internal | |
| icc | |
| masq | |
| snat | |
| bindLocalhost | |
| wsl2Mirrored | |
| numBoolParams = iota | |
| ) | |
| nftables.Enable() | |
| t.Cleanup(func() { nftables.Disable() }) // Cleanup instead of defer, this func returns before the parallel subtests finish. | |
| for i := range 1 << numBoolParams { | |
| p := func(n int64) bool { return (i & n) == n } |
Signed-off-by: Rob Murray <[email protected]>
- What I did
Add
TestNftabler- nftables equivalent toTestIptabler... it runs the nftabler with fairly exhaustive combinations of options (not all of which make sense, but this checks there's nothing crashy).There are lots of results files ... and not much in them yet (because the nftabler is just an outline so far). But, for upcoming changes as nftables rules are added, it'll show the effect.
- How I did it
- How to verify it
- Human readable description for the release notes