Skip to content

Commit

Permalink
Update UDP outbound tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronH88 committed Nov 28, 2024
1 parent ad4fa8f commit 4babfdc
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions pkg/services/udp_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ func TestUDPProxyServiceInbound(t *testing.T) {
if err == nil {
t.Errorf("net UDPProxyServiceInbound fail case error")
}

return
} else {
if err != nil {
t.Errorf("net UDPProxyServiceInbound error")
}
} else if err != nil {
t.Errorf("net UDPProxyServiceInbound error")
}
})
}
Expand All @@ -101,7 +100,6 @@ func TestUDPProxyServiceOutbound(t *testing.T) {
var mockNetceptor *mock_services.MockNetcForUDPProxy
var mockNetter *mock_net_interface.MockNetterUDP
var mockPacketCon *mock_netceptor.MockPacketConner
logger := logger.NewReceptorLogger("test")
type testCase struct {
name string
service string
Expand Down Expand Up @@ -131,21 +129,7 @@ func TestUDPProxyServiceOutbound(t *testing.T) {
calls: func() {
mockNetter.EXPECT().ResolveUDPAddr(gomock.Any(), gomock.Any()).Return(nil, nil)
mockNetceptor.EXPECT().ListenPacketAndAdvertise(gomock.Any(), gomock.Any()).Return(mockPacketCon, nil)
mockPacketCon.EXPECT().ReadFrom(gomock.Any()).Return(0, nil, errors.New("Read From error"))
},
},
{
name: "Fail Dial UDP",
calls: func() {
mockNetter.EXPECT().ResolveUDPAddr(gomock.Any(), gomock.Any()).Return(nil, nil)
mockNetceptor.EXPECT().ListenPacketAndAdvertise(gomock.Any(), gomock.Any()).Return(mockPacketCon, nil)
gomock.InOrder(
mockPacketCon.EXPECT().ReadFrom(gomock.Any()).Return(0, netceptor.Addr{}, nil),
mockPacketCon.EXPECT().ReadFrom(gomock.Any()).Return(0, nil, errors.New("Read From error")).AnyTimes(),
)
mockNetceptor.EXPECT().GetLogger().Return(logger).AnyTimes()
mockNetter.EXPECT().DialUDP(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("Dial UDP error"))

mockPacketCon.EXPECT().ReadFrom(gomock.Any()).Return(0, nil, errors.New("Read From error")).AnyTimes()
},
},
}
Expand All @@ -159,13 +143,11 @@ func TestUDPProxyServiceOutbound(t *testing.T) {
if err == nil {
t.Errorf("net UDPProxyServiceOutbound fail case error")
}

return
} else {
if err != nil {
t.Errorf("net UDPProxyServiceOutbound error")
}
} else if err != nil {
t.Errorf("net UDPProxyServiceOutbound error")
}
})
}

}

0 comments on commit 4babfdc

Please sign in to comment.