Skip to content

Commit

Permalink
Add udp dialer test (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-at-redhat authored Oct 17, 2024
1 parent 46dd998 commit 21ce884
Showing 1 changed file with 55 additions and 15 deletions.
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")
}
})
}
}

0 comments on commit 21ce884

Please sign in to comment.