File tree 4 files changed +39
-2
lines changed
4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -1102,3 +1102,15 @@ func TestMultipleTorrentsWithEncryption(t *testing.T) {
1102
1102
tr .DownloadAll ()
1103
1103
client .WaitAll ()
1104
1104
}
1105
+
1106
+ func TestClientAddressInUse (t * testing.T ) {
1107
+ s , _ := NewUtpSocket ("udp" , ":50007" )
1108
+ if s != nil {
1109
+ defer s .Close ()
1110
+ }
1111
+ cfg := TestingConfig ()
1112
+ cfg .ListenAddr = ":50007"
1113
+ cl , err := NewClient (cfg )
1114
+ require .Error (t , err )
1115
+ require .Nil (t , cl )
1116
+ }
Original file line number Diff line number Diff line change @@ -7,5 +7,10 @@ import (
7
7
)
8
8
9
9
func NewUtpSocket (network , addr string ) (utpSocket , error ) {
10
- return utp .NewSocket (network , addr )
10
+ s , err := utp .NewSocket (network , addr )
11
+ if s == nil {
12
+ return nil , err
13
+ } else {
14
+ return s , err
15
+ }
11
16
}
Original file line number Diff line number Diff line change @@ -7,5 +7,10 @@ import (
7
7
)
8
8
9
9
func NewUtpSocket (network , addr string ) (utpSocket , error ) {
10
- return utp .NewSocket (network , addr )
10
+ s , err := utp .NewSocket (network , addr )
11
+ if s == nil {
12
+ return nil , err
13
+ } else {
14
+ return s , err
15
+ }
11
16
}
Original file line number Diff line number Diff line change
1
+ package torrent
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestNewUtpSocketErrorNilInterface (t * testing.T ) {
10
+ s , err := NewUtpSocket ("fix" , "your:language" )
11
+ assert .Error (t , err )
12
+ if s != nil {
13
+ t .Fatalf ("expected nil, got %#v" , s )
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments