summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-01-31 13:46:02 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-31 13:47:57 -0800
commitc5e3c1c7bd5b7d1dc389fd93ac0cd56cdb4d9ac9 (patch)
tree4800c150420f9e44a00a732c1dae89fe6f99b5bf /pkg
parentb4f8a925283eaca32820e7977706768343bf04b8 (diff)
Use closure for IPv6 testContext cleanup
PiperOrigin-RevId: 354827491
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/network/ipv6/icmp_test.go28
1 files changed, 11 insertions, 17 deletions
diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go
index 60404c78b..92f9ee2c2 100644
--- a/pkg/tcpip/network/ipv6/icmp_test.go
+++ b/pkg/tcpip/network/ipv6/icmp_test.go
@@ -492,8 +492,6 @@ func visitStats(v reflect.Value, f func(string, *tcpip.StatCounter)) {
}
type testContext struct {
- t *testing.T
-
s0 *stack.Stack
s1 *stack.Stack
@@ -511,8 +509,6 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab
func newTestContext(t *testing.T) *testContext {
c := &testContext{
- t: t,
-
s0: stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
@@ -566,21 +562,19 @@ func newTestContext(t *testing.T) *testContext {
}},
)
- t.Cleanup(c.cleanup)
-
- return c
-}
+ t.Cleanup(func() {
+ if err := c.s0.RemoveNIC(nicID); err != nil {
+ t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err)
+ }
+ if err := c.s1.RemoveNIC(nicID); err != nil {
+ t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err)
+ }
-func (c *testContext) cleanup() {
- if err := c.s0.RemoveNIC(nicID); err != nil {
- c.t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err)
- }
- if err := c.s1.RemoveNIC(nicID); err != nil {
- c.t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err)
- }
+ c.linkEP0.Close()
+ c.linkEP1.Close()
+ })
- c.linkEP0.Close()
- c.linkEP1.Close()
+ return c
}
type routeArgs struct {