-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a quick set of client/rpcproxy.ServerEndpoint equality tests
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package rpcproxy | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// func (k *EndpointKey) Equal(x *EndpointKey) { | ||
func TestServerEndpointKey_Equal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
k1 *EndpointKey | ||
k2 *EndpointKey | ||
equal bool | ||
}{ | ||
{ | ||
name: "equal", | ||
k1: &EndpointKey{name: "k1"}, | ||
k2: &EndpointKey{name: "k1"}, | ||
equal: true, | ||
}, | ||
{ | ||
name: "not equal", | ||
k1: &EndpointKey{name: "k1"}, | ||
k2: &EndpointKey{name: "k2"}, | ||
equal: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
if test.k1.Equal(test.k2) != test.equal { | ||
t.Errorf("fixture %s failed forward comparison", test.name) | ||
} | ||
|
||
if test.k2.Equal(test.k1) != test.equal { | ||
t.Errorf("fixture %s failed reverse comparison", test.name) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package rpcproxy_test | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/client/rpcproxy" | ||
) | ||
|
||
// func (k *rpcproxy.EndpointKey) Equal(x *rpcproxy.EndpointKey) { | ||
func TestServerEndpointKey_Equal(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
s1 *rpcproxy.ServerEndpoint | ||
s2 *rpcproxy.ServerEndpoint | ||
equal bool | ||
}{ | ||
{ | ||
name: "equal", | ||
s1: &rpcproxy.ServerEndpoint{Name: "k1"}, | ||
s2: &rpcproxy.ServerEndpoint{Name: "k1"}, | ||
equal: true, | ||
}, | ||
{ | ||
name: "not equal", | ||
s1: &rpcproxy.ServerEndpoint{Name: "k1"}, | ||
s2: &rpcproxy.ServerEndpoint{Name: "k2"}, | ||
equal: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
if test.s1.Key().Equal(test.s2.Key()) != test.equal { | ||
t.Errorf("fixture %s failed forward comparison", test.name) | ||
} | ||
|
||
if test.s2.Key().Equal(test.s1.Key()) != test.equal { | ||
t.Errorf("fixture %s failed reverse comparison", test.name) | ||
} | ||
} | ||
} | ||
|
||
// func (k *rpcproxy.ServerEndpoint) String() { | ||
func TestServerEndpoint_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
s *rpcproxy.ServerEndpoint | ||
str string | ||
}{ | ||
{ | ||
name: "name", | ||
s: &rpcproxy.ServerEndpoint{Name: "s"}, | ||
str: "s (:)", | ||
}, | ||
{ | ||
name: "name, host, port", | ||
s: &rpcproxy.ServerEndpoint{ | ||
Name: "s", | ||
Host: "127.0.0.1", | ||
Port: "4647", | ||
}, | ||
str: "s (tcp:127.0.0.1:4647)", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
if test.s.Addr == nil && (test.s.Host != "" && test.s.Port != "") { | ||
fmt.Printf("Setting addr\n") | ||
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(test.s.Host, test.s.Port)) | ||
if err == nil { | ||
test.s.Addr = addr | ||
} | ||
} | ||
if test.s.String() != test.str { | ||
t.Errorf("fixture %q failed: %q vs %q", test.name, test.s.String(), test.str) | ||
} | ||
} | ||
} |