Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add udp dialer test #1179

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions pkg/backends/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ func TestNewUDPListener(t *testing.T) {
logger *logger.ReceptorLogger
}

goodLogger := logger.NewReceptorLogger("UDPtest")
goodUDPListener := &UDPListener{
laddr: &net.UDPAddr{},
conn: &net.UDPConn{},
sessChan: make(chan *UDPListenerSession),
sessRegLock: sync.RWMutex{},
sessionRegistry: make(map[string]*UDPListenerSession),
logger: goodLogger,
}
tests := []struct {
name string
args args
Expand All @@ -34,10 +25,9 @@ func TestNewUDPListener(t *testing.T) {
{
name: "Positive",
args: args{
address: "127.0.0.1:9998",
logger: goodLogger,
address: "127.0.0.1:9997",
logger: logger.NewReceptorLogger("UDPtest"),
},
want: goodUDPListener,
wantErr: false,
},
}
Expand Down Expand Up @@ -65,7 +55,6 @@ func TestUDPListenerStart(t *testing.T) {
logger *logger.ReceptorLogger
}

goodLogger := logger.NewReceptorLogger("UDPtest")
type args struct {
ctx context.Context
wg *sync.WaitGroup
Expand All @@ -88,7 +77,7 @@ func TestUDPListenerStart(t *testing.T) {
conn: &net.UDPConn{},
sessChan: make(chan *UDPListenerSession),
sessionRegistry: make(map[string]*UDPListenerSession),
logger: goodLogger,
logger: logger.NewReceptorLogger("UDPtest"),
},
args: args{
ctx: context.Background(),
Expand All @@ -115,7 +104,7 @@ func TestUDPListenerStart(t *testing.T) {
}
got, err := b.Start(tt.args.ctx, tt.args.wg)
if (err != nil) != tt.wantErr {
t.Errorf("UDPListener.Start() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("UDPListener.Start() error = %+v, wantErr %+v", err, tt.wantErr)

return
}
Expand All @@ -125,3 +114,54 @@ func TestUDPListenerStart(t *testing.T) {
})
}
}

func TestUDPDialerStart(t *testing.T) {
type fields struct {
address string
redial bool
logger *logger.ReceptorLogger
}
type args struct {
ctx context.Context
wg *sync.WaitGroup
}
tests := []struct {
name string
fields fields
args args
want chan netceptor.BackendSession
wantErr bool
}{
{
name: "Positive",
fields: fields{
address: "127.0.0.1:9998",
redial: true,
logger: logger.NewReceptorLogger("UDPtest"),
},
args: args{
ctx: context.Background(),
wg: &sync.WaitGroup{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := &UDPDialer{
address: tt.fields.address,
redial: tt.fields.redial,
logger: tt.fields.logger,
}
got, err := b.Start(tt.args.ctx, tt.args.wg)
if (err != nil) != tt.wantErr {
t.Errorf("UDPDialer.Start() error = %+v, wantErr %+v", err, tt.wantErr)

return
}
if got == nil {
t.Errorf("UDPDialer.Start() returned nil")
}
})
}
}