2014-02-11 19:48:44 -05:00
|
|
|
package nat
|
2013-11-14 01:08:08 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSortUniquePorts(t *testing.T) {
|
|
|
|
ports := []Port{
|
|
|
|
Port("6379/tcp"),
|
|
|
|
Port("22/tcp"),
|
|
|
|
}
|
|
|
|
|
2014-02-11 19:48:44 -05:00
|
|
|
Sort(ports, func(ip, jp Port) bool {
|
2013-11-14 01:08:08 -05:00
|
|
|
return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp")
|
|
|
|
})
|
|
|
|
|
|
|
|
first := ports[0]
|
|
|
|
if fmt.Sprint(first) != "22/tcp" {
|
|
|
|
t.Log(fmt.Sprint(first))
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSortSamePortWithDifferentProto(t *testing.T) {
|
|
|
|
ports := []Port{
|
|
|
|
Port("8888/tcp"),
|
|
|
|
Port("8888/udp"),
|
|
|
|
Port("6379/tcp"),
|
|
|
|
Port("6379/udp"),
|
|
|
|
}
|
|
|
|
|
2014-02-11 19:48:44 -05:00
|
|
|
Sort(ports, func(ip, jp Port) bool {
|
2013-11-14 01:08:08 -05:00
|
|
|
return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && ip.Proto() == "tcp")
|
|
|
|
})
|
|
|
|
|
|
|
|
first := ports[0]
|
|
|
|
if fmt.Sprint(first) != "6379/tcp" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|