2008-12-18 16:42:39 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing";
|
|
|
|
)
|
|
|
|
|
2009-01-16 15:16:31 -07:00
|
|
|
type portTest struct {
|
2009-11-05 00:16:46 -07:00
|
|
|
netw string;
|
|
|
|
name string;
|
|
|
|
port int;
|
|
|
|
ok bool;
|
2008-12-18 16:42:39 -07:00
|
|
|
}
|
|
|
|
|
2009-11-05 00:16:46 -07:00
|
|
|
var porttests = []portTest{
|
|
|
|
portTest{"tcp", "echo", 7, true},
|
|
|
|
portTest{"tcp", "discard", 9, true},
|
|
|
|
portTest{"tcp", "systat", 11, true},
|
|
|
|
portTest{"tcp", "daytime", 13, true},
|
|
|
|
portTest{"tcp", "chargen", 19, true},
|
|
|
|
portTest{"tcp", "ftp-data", 20, true},
|
|
|
|
portTest{"tcp", "ftp", 21, true},
|
|
|
|
portTest{"tcp", "ssh", 22, true},
|
|
|
|
portTest{"tcp", "telnet", 23, true},
|
|
|
|
portTest{"tcp", "smtp", 25, true},
|
|
|
|
portTest{"tcp", "time", 37, true},
|
|
|
|
portTest{"tcp", "domain", 53, true},
|
|
|
|
portTest{"tcp", "gopher", 70, true},
|
|
|
|
portTest{"tcp", "finger", 79, true},
|
|
|
|
portTest{"tcp", "http", 80, true},
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2009-11-05 00:16:46 -07:00
|
|
|
portTest{"udp", "echo", 7, true},
|
|
|
|
portTest{"udp", "tacacs", 49, true},
|
|
|
|
portTest{"udp", "tftp", 69, true},
|
|
|
|
portTest{"udp", "bootpc", 68, true},
|
|
|
|
portTest{"udp", "bootps", 67, true},
|
|
|
|
portTest{"udp", "domain", 53, true},
|
|
|
|
portTest{"udp", "ntp", 123, true},
|
|
|
|
portTest{"udp", "snmp", 161, true},
|
|
|
|
portTest{"udp", "syslog", 514, true},
|
|
|
|
portTest{"udp", "nfs", 2049, true},
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2009-11-05 00:16:46 -07:00
|
|
|
portTest{"--badnet--", "zzz", 0, false},
|
|
|
|
portTest{"tcp", "--badport--", 0, false},
|
2009-03-03 09:39:12 -07:00
|
|
|
}
|
2008-12-18 16:42:39 -07:00
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
func TestLookupPort(t *testing.T) {
|
2008-12-18 16:42:39 -07:00
|
|
|
for i := 0; i < len(porttests); i++ {
|
|
|
|
tt := porttests[i];
|
2009-03-05 16:48:12 -07:00
|
|
|
if port, err := LookupPort(tt.netw, tt.name); port != tt.port || (err == nil) != tt.ok {
|
|
|
|
t.Errorf("LookupPort(%q, %q) = %v, %s; want %v",
|
|
|
|
tt.netw, tt.name, port, err, tt.port);
|
2008-12-18 16:42:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|