-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
b192194
commit 53bbe68
Showing
1 changed file
with
32 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,32 @@ | ||
package addr | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
) | ||
|
||
func TestAddressSorting(t *testing.T) { | ||
u1 := newAddrOrFatal(t, "/ip4/152.12.23.53/udp/1234/utp") | ||
u2l := newAddrOrFatal(t, "/ip4/127.0.0.1/udp/1234/utp") | ||
local := newAddrOrFatal(t, "/ip4/127.0.0.1/tcp/1234") | ||
norm := newAddrOrFatal(t, "/ip4/6.5.4.3/tcp/1234") | ||
|
||
l := AddrList{local, u1, u2l, norm} | ||
sort.Sort(l) | ||
|
||
if !l[0].Equal(u2l) { | ||
t.Fatal("expected utp local addr to be sorted first: ", l[0]) | ||
} | ||
|
||
if !l[1].Equal(u1) { | ||
t.Fatal("expected utp addr to be sorted second") | ||
} | ||
|
||
if !l[2].Equal(local) { | ||
t.Fatal("expected tcp localhost addr thid") | ||
} | ||
|
||
if !l[3].Equal(norm) { | ||
t.Fatal("expected normal addr last") | ||
} | ||
} |