Fixing some tests

This commit is contained in:
Armon Dadgar 2014-01-09 17:22:01 -08:00
parent c0029c6967
commit 028829a36d
3 changed files with 45 additions and 6 deletions

View File

@ -213,13 +213,18 @@ func TestCatalogListNodes(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
if len(out) != 1 { if len(out) != 2 {
t.Fatalf("bad: %v", out) t.Fatalf("bad: %v", out)
} }
if out[0].Node != "foo" {
// Server node is auto added from Serf
if out[0].Node != s1.config.NodeName {
t.Fatalf("bad: %v", out) t.Fatalf("bad: %v", out)
} }
if out[0].Address != "127.0.0.1" { if out[1].Node != "foo" {
t.Fatalf("bad: %v", out)
}
if out[1].Address != "127.0.0.1" {
t.Fatalf("bad: %v", out) t.Fatalf("bad: %v", out)
} }
} }

View File

@ -40,11 +40,16 @@ func TestHealth_ChecksInState(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
if len(checks) != 1 { if len(checks) != 2 {
t.Fatalf("Bad: %v", checks) t.Fatalf("Bad: %v", checks)
} }
if checks[0].Name != "memory utilization" {
t.Fatalf("Bad: %v", checks) // First check is automatically added for the server node
if checks[0].CheckID != serfCheckID {
t.Fatalf("Bad: %v", checks[0])
}
if checks[1].Name != "memory utilization" {
t.Fatalf("Bad: %v", checks[1])
} }
} }

View File

@ -1,6 +1,7 @@
package consul package consul
import ( import (
"github.com/hashicorp/serf/serf"
"testing" "testing"
) )
@ -31,3 +32,31 @@ func TestIsPrivateIP(t *testing.T) {
t.Fatalf("bad") t.Fatalf("bad")
} }
} }
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")
}
}