Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package net |
| 6 | |
| 7 | import ( |
Mikio Hara | 484cc67 | 2014-09-18 19:17:55 +0900 | [diff] [blame] | 8 | "runtime" |
Robert Griesemer | a3d1045 | 2009-12-15 15:35:38 -0800 | [diff] [blame] | 9 | "testing" |
Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 10 | ) |
| 11 | |
Mikio Hara | f77e10f | 2015-05-01 12:38:42 +0900 | [diff] [blame] | 12 | var portTests = []struct { |
| 13 | network string |
| 14 | name string |
| 15 | port int |
| 16 | ok bool |
| 17 | }{ |
Robert Griesemer | 3478891 | 2010-10-22 10:06:33 -0700 | [diff] [blame] | 18 | {"tcp", "echo", 7, true}, |
| 19 | {"tcp", "discard", 9, true}, |
| 20 | {"tcp", "systat", 11, true}, |
| 21 | {"tcp", "daytime", 13, true}, |
| 22 | {"tcp", "chargen", 19, true}, |
| 23 | {"tcp", "ftp-data", 20, true}, |
| 24 | {"tcp", "ftp", 21, true}, |
| 25 | {"tcp", "telnet", 23, true}, |
| 26 | {"tcp", "smtp", 25, true}, |
| 27 | {"tcp", "time", 37, true}, |
| 28 | {"tcp", "domain", 53, true}, |
Robert Griesemer | 3478891 | 2010-10-22 10:06:33 -0700 | [diff] [blame] | 29 | {"tcp", "finger", 79, true}, |
Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 30 | |
Robert Griesemer | 3478891 | 2010-10-22 10:06:33 -0700 | [diff] [blame] | 31 | {"udp", "echo", 7, true}, |
| 32 | {"udp", "tftp", 69, true}, |
| 33 | {"udp", "bootpc", 68, true}, |
| 34 | {"udp", "bootps", 67, true}, |
| 35 | {"udp", "domain", 53, true}, |
| 36 | {"udp", "ntp", 123, true}, |
| 37 | {"udp", "snmp", 161, true}, |
| 38 | {"udp", "syslog", 514, true}, |
Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 39 | |
Robert Griesemer | 3478891 | 2010-10-22 10:06:33 -0700 | [diff] [blame] | 40 | {"--badnet--", "zzz", 0, false}, |
| 41 | {"tcp", "--badport--", 0, false}, |
Russ Cox | be2edb5 | 2009-03-03 08:39:12 -0800 | [diff] [blame] | 42 | } |
Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 43 | |
Russ Cox | 839a684 | 2009-01-20 14:40:40 -0800 | [diff] [blame] | 44 | func TestLookupPort(t *testing.T) { |
Mikio Hara | 484cc67 | 2014-09-18 19:17:55 +0900 | [diff] [blame] | 45 | switch runtime.GOOS { |
| 46 | case "nacl": |
Mikio Hara | f77e10f | 2015-05-01 12:38:42 +0900 | [diff] [blame] | 47 | t.Skipf("not supported on %s", runtime.GOOS) |
Mikio Hara | 484cc67 | 2014-09-18 19:17:55 +0900 | [diff] [blame] | 48 | } |
| 49 | |
Mikio Hara | f77e10f | 2015-05-01 12:38:42 +0900 | [diff] [blame] | 50 | for _, tt := range portTests { |
| 51 | if port, err := LookupPort(tt.network, tt.name); port != tt.port || (err == nil) != tt.ok { |
| 52 | t.Errorf("LookupPort(%q, %q) = %v, %v; want %v", tt.network, tt.name, port, err, tt.port) |
Russ Cox | 83348f9 | 2008-12-18 15:42:39 -0800 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |