nomad: testing status endpoint

This commit is contained in:
Armon Dadgar
2015-06-04 13:26:16 +02:00
parent 6e0140c6ff
commit 3ee5d2dce2
2 changed files with 86 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package testutil
import "time"
import (
"testing"
"time"
)
type testFn func() (bool, error)
type errorFn func(error)
@@ -22,3 +25,16 @@ func WaitForResult(test testFn, error errorFn) {
}
}
}
type rpcFn func(string, interface{}, interface{}) error
func WaitForLeader(t *testing.T, rpc rpcFn) {
WaitForResult(func() (bool, error) {
args := struct{}{}
var leader string
err := rpc("Status.Leader", args, &leader)
return leader != "", err
}, func(err error) {
t.Fatalf("failed to find leader: %v", err)
})
}