-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
451f69e
commit b6105fc
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
}) | ||
} | ||
} |