github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/client/rpcproxy/server_endpoint_test.go (about) 1 package rpcproxy 2 3 import ( 4 "fmt" 5 "net" 6 "testing" 7 ) 8 9 // func (k *EndpointKey) Equal(x *EndpointKey) { 10 func TestServerEndpointKey_Equal(t *testing.T) { 11 tests := []struct { 12 name string 13 s1 *ServerEndpoint 14 s2 *ServerEndpoint 15 equal bool 16 }{ 17 { 18 name: "equal", 19 s1: &ServerEndpoint{Name: "k1"}, 20 s2: &ServerEndpoint{Name: "k1"}, 21 equal: true, 22 }, 23 { 24 name: "not equal", 25 s1: &ServerEndpoint{Name: "k1"}, 26 s2: &ServerEndpoint{Name: "k2"}, 27 equal: false, 28 }, 29 } 30 31 for _, test := range tests { 32 if test.s1.Key().Equal(test.s2.Key()) != test.equal { 33 t.Errorf("fixture %s failed forward comparison", test.name) 34 } 35 36 if test.s2.Key().Equal(test.s1.Key()) != test.equal { 37 t.Errorf("fixture %s failed reverse comparison", test.name) 38 } 39 } 40 } 41 42 // func (k *ServerEndpoint) String() { 43 func TestServerEndpoint_String(t *testing.T) { 44 tests := []struct { 45 name string 46 s *ServerEndpoint 47 str string 48 }{ 49 { 50 name: "name", 51 s: &ServerEndpoint{Name: "s"}, 52 str: "s (:)", 53 }, 54 { 55 name: "name, host, port", 56 s: &ServerEndpoint{ 57 Name: "s", 58 Host: "127.0.0.1", 59 Port: "4647", 60 }, 61 str: "s (tcp:127.0.0.1:4647)", 62 }, 63 } 64 65 for _, test := range tests { 66 if test.s.Addr == nil && (test.s.Host != "" && test.s.Port != "") { 67 fmt.Printf("Setting addr\n") 68 addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(test.s.Host, test.s.Port)) 69 if err == nil { 70 test.s.Addr = addr 71 } 72 } 73 if test.s.String() != test.str { 74 t.Errorf("fixture %q failed: %q vs %q", test.name, test.s.String(), test.str) 75 } 76 } 77 }