github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/src/net/port_test.go (about)

     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 (
     8  	"runtime"
     9  	"testing"
    10  )
    11  
    12  var portTests = []struct {
    13  	network string
    14  	name    string
    15  	port    int
    16  	ok      bool
    17  }{
    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},
    29  	{"tcp", "finger", 79, true},
    30  	{"tcp", "42", 42, true},
    31  
    32  	{"udp", "echo", 7, true},
    33  	{"udp", "tftp", 69, true},
    34  	{"udp", "bootpc", 68, true},
    35  	{"udp", "bootps", 67, true},
    36  	{"udp", "domain", 53, true},
    37  	{"udp", "ntp", 123, true},
    38  	{"udp", "snmp", 161, true},
    39  	{"udp", "syslog", 514, true},
    40  	{"udp", "42", 42, true},
    41  
    42  	{"--badnet--", "zzz", 0, false},
    43  	{"tcp", "--badport--", 0, false},
    44  }
    45  
    46  func TestLookupPort(t *testing.T) {
    47  	switch runtime.GOOS {
    48  	case "nacl":
    49  		t.Skipf("not supported on %s", runtime.GOOS)
    50  	}
    51  
    52  	for _, tt := range portTests {
    53  		if port, err := LookupPort(tt.network, tt.name); port != tt.port || (err == nil) != tt.ok {
    54  			t.Errorf("LookupPort(%q, %q) = %v, %v; want %v", tt.network, tt.name, port, err, tt.port)
    55  		}
    56  	}
    57  }