Make ipv6 test contexts consistent with ipv4

- Return by value rather than by pointer
- buildRoute takes *testing.T as its first argument

Updates #6910.

PiperOrigin-RevId: 429400727
This commit is contained in:
Tamir Duberstein
2022-02-17 14:21:09 -08:00
committed by gVisor bot
parent 2822b56f30
commit 8dda736af8
3 changed files with 10 additions and 10 deletions
+4 -4
View File
@@ -201,13 +201,13 @@ type testContext struct {
s *stack.Stack
}
func newTestContext(clock tcpip.Clock) *testContext {
func newTestContext(clock tcpip.Clock) testContext {
s := stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6, udp.NewProtocol},
Clock: clock,
})
return &testContext{s: s}
return testContext{s: s}
}
func (c *testContext) cleanup() {
@@ -409,7 +409,7 @@ func (e endpointWithResolutionCapability) Capabilities() stack.LinkEndpointCapab
return e.LinkEndpoint.Capabilities() | stack.CapabilityResolutionRequired
}
func newMultiStackTestContext(t *testing.T) *multiStackTestContext {
func newMultiStackTestContext(t *testing.T) multiStackTestContext {
clock := faketime.NewManualClock()
s0 := stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{NewProtocol},
@@ -421,7 +421,7 @@ func newMultiStackTestContext(t *testing.T) *multiStackTestContext {
TransportProtocols: []stack.TransportProtocolFactory{icmp.NewProtocol6},
Clock: clock,
})
c := &multiStackTestContext{
c := multiStackTestContext{
s0: s0,
s1: s1,
clock: clock,
+4 -4
View File
@@ -2605,7 +2605,7 @@ func TestWriteStats(t *testing.T) {
ep := iptestutil.NewMockLinkEndpoint(header.IPv6MinimumMTU, &tcpip.ErrInvalidEndpointState{}, test.allowPackets)
defer ep.Close()
rt := buildRoute(c, t, ep)
rt := buildRoute(t, c, ep)
test.setup(t, rt.Stack())
nWritten := 0
@@ -2638,7 +2638,7 @@ func TestWriteStats(t *testing.T) {
}
}
func buildRoute(c *testContext, t *testing.T, ep stack.LinkEndpoint) *stack.Route {
func buildRoute(t *testing.T, c testContext, ep stack.LinkEndpoint) *stack.Route {
s := c.s
if err := s.CreateNIC(1, ep); err != nil {
t.Fatalf("CreateNIC(1, _) failed: %s", err)
@@ -2813,7 +2813,7 @@ func TestFragmentationWritePacket(t *testing.T) {
ep := iptestutil.NewMockLinkEndpoint(ft.mtu, nil, math.MaxInt32)
defer ep.Close()
r := buildRoute(c, t, ep)
r := buildRoute(t, c, ep)
err := r.WritePacket(stack.NetworkHeaderParams{
Protocol: tcp.ProtocolNumber,
TTL: ttl,
@@ -2915,7 +2915,7 @@ func TestFragmentationErrors(t *testing.T) {
ep := iptestutil.NewMockLinkEndpoint(ft.mtu, ft.mockError, ft.allowPackets)
defer ep.Close()
r := buildRoute(c, t, ep)
r := buildRoute(t, c, ep)
err := r.WritePacket(stack.NetworkHeaderParams{
Protocol: tcp.ProtocolNumber,
TTL: ttl,
+2 -2
View File
@@ -69,7 +69,7 @@ func (c *mldTestContext) cleanup() {
c.s.Wait()
}
func newMLDTestContext() *mldTestContext {
func newMLDTestContext() mldTestContext {
s := stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{ipv6.NewProtocolWithOptions(ipv6.Options{
MLD: ipv6.MLDOptions{
@@ -77,7 +77,7 @@ func newMLDTestContext() *mldTestContext {
},
})},
})
return &mldTestContext{s: s}
return mldTestContext{s: s}
}
func TestIPv6JoinLeaveSolicitedNodeAddressPerformsMLD(t *testing.T) {