open-consul/consul/util_test.go

63 lines
1.1 KiB
Go
Raw Normal View History

2013-12-12 19:07:14 +00:00
package consul
import (
2014-01-10 01:22:01 +00:00
"github.com/hashicorp/serf/serf"
2013-12-12 19:07:14 +00:00
"testing"
)
func TestStrContains(t *testing.T) {
l := []string{"a", "b", "c"}
if !strContains(l, "b") {
t.Fatalf("should contain")
}
if strContains(l, "d") {
t.Fatalf("should not contain")
}
}
2013-12-31 23:44:17 +00:00
func TestIsPrivateIP(t *testing.T) {
if !isPrivateIP("192.168.1.1") {
t.Fatalf("bad")
}
if !isPrivateIP("172.16.45.100") {
t.Fatalf("bad")
}
if !isPrivateIP("10.1.2.3") {
t.Fatalf("bad")
}
if isPrivateIP("8.8.8.8") {
t.Fatalf("bad")
}
if isPrivateIP("127.0.0.1") {
t.Fatalf("bad")
}
}
2014-01-10 01:22:01 +00:00
func TestIsConsulServer(t *testing.T) {
m := serf.Member{
Role: "consul:east-aws:10000",
}
valid, dc, port := isConsulServer(m)
if !valid || dc != "east-aws" || port != 10000 {
t.Fatalf("bad: %v %v %v", valid, dc, port)
}
}
func TestIsConsulNode(t *testing.T) {
m := serf.Member{
Role: "node:east-aws",
}
valid, dc := isConsulNode(m)
if !valid || dc != "east-aws" {
t.Fatalf("bad: %v %v %v", valid, dc)
}
}
func TestByteConversion(t *testing.T) {
var val uint64 = 2 << 50
raw := uint64ToBytes(val)
if bytesToUint64(raw) != val {
t.Fatalf("no match")
}
}