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 9cd5ea8
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions pkg/services/udp_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"github.com/ansible/receptor/pkg/logger"
"github.com/ansible/receptor/pkg/netceptor"
"github.com/ansible/receptor/pkg/netceptor/mock_netceptor"
"github.com/ansible/receptor/pkg/services/mock_services"

mock_net_interface "github.com/ansible/receptor/pkg/services/interfaces/mock_interfaces"
"github.com/ansible/receptor/pkg/services/mock_services"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -85,11 +84,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 +99,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 +128,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 +142,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 9cd5ea8

Please sign in to comment.