Use closure for IPv6 testContext cleanup
PiperOrigin-RevId: 354827491
This commit is contained in:
parent
b4f8a92528
commit
c5e3c1c7bd
|
@ -492,8 +492,6 @@ func visitStats(v reflect.Value, f func(string, *tcpip.StatCounter)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type testContext struct {
|
type testContext struct {
|
||||||
t *testing.T
|
|
||||||
|
|
||||||
s0 *stack.Stack
|
s0 *stack.Stack
|
||||||
s1 *stack.Stack
|
s1 *stack.Stack
|
||||||
|
|
||||||
|
@ -511,8 +509,6 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab
|
||||||
|
|
||||||
func newTestContext(t *testing.T) *testContext {
|
func newTestContext(t *testing.T) *testContext {
|
||||||
c := &testContext{
|
c := &testContext{
|
||||||
t: t,
|
|
||||||
|
|
||||||
s0: stack.New(stack.Options{
|
s0: stack.New(stack.Options{
|
||||||
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
|
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
|
||||||
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
|
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
|
||||||
|
@ -566,21 +562,19 @@ func newTestContext(t *testing.T) *testContext {
|
||||||
}},
|
}},
|
||||||
)
|
)
|
||||||
|
|
||||||
t.Cleanup(c.cleanup)
|
t.Cleanup(func() {
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *testContext) cleanup() {
|
|
||||||
if err := c.s0.RemoveNIC(nicID); err != nil {
|
if err := c.s0.RemoveNIC(nicID); err != nil {
|
||||||
c.t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err)
|
t.Errorf("c.s0.RemoveNIC(%d): %s", nicID, err)
|
||||||
}
|
}
|
||||||
if err := c.s1.RemoveNIC(nicID); err != nil {
|
if err := c.s1.RemoveNIC(nicID); err != nil {
|
||||||
c.t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err)
|
t.Errorf("c.s1.RemoveNIC(%d): %s", nicID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.linkEP0.Close()
|
c.linkEP0.Close()
|
||||||
c.linkEP1.Close()
|
c.linkEP1.Close()
|
||||||
|
})
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
type routeArgs struct {
|
type routeArgs struct {
|
||||||
|
|
Loading…
Reference in New Issue