Skip to content

Commit

Permalink
Add udp test
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-at-redhat committed Oct 16, 2024
1 parent 451f69e commit 1dfa1b7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/backends/udp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package backends

import (
"net"
"sync"
"testing"

"github.com/ansible/receptor/pkg/logger"
)

func TestNewUDPListener(t *testing.T) {
type args struct {
address string
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
want *UDPListener
wantErr bool
}{
{
name: "Positive",
args: args{
address: "127.0.0.1:9998",
logger: goodLogger,
},
want: goodUDPListener,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewUDPListener(tt.args.address, tt.args.logger)
if (err != nil) != tt.wantErr {
t.Errorf("NewUDPListener() error = %+v, wantErr %+v", err, tt.wantErr)

return
}
if got == nil {
t.Errorf("NewUDPListener(): want UDP Listener, got nil")
}
})
}
}

0 comments on commit 1dfa1b7

Please sign in to comment.