add Probers to Probe pkgs.

This commit is contained in:
Mike Danese
2015-01-27 10:00:21 -08:00
parent a298402bd4
commit 6eb0b89cbd
7 changed files with 38 additions and 11 deletions

View File

@@ -27,11 +27,17 @@ import (
"github.com/golang/glog"
)
var client = &http.Client{}
func New() HTTPProber {
return HTTPProber{&http.Client{}}
}
type HTTPProber struct {
client HTTPGetInterface
}
// Probe returns a ProbeRunner capable of running an http check.
func Probe(host string, port int, path string) (probe.Status, error) {
return DoHTTPProbe(formatURL(host, port, path), client)
func (pr *HTTPProber) Probe(host string, port int, path string) (probe.Status, error) {
return DoHTTPProbe(formatURL(host, port, path), pr.client)
}
type HTTPGetInterface interface {

View File

@@ -46,6 +46,7 @@ func TestFormatURL(t *testing.T) {
}
func TestHTTPProbeChecker(t *testing.T) {
prober := New()
testCases := []struct {
status int
health probe.Status
@@ -70,7 +71,7 @@ func TestHTTPProbeChecker(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
health, err := Probe(host, p, "")
health, err := prober.Probe(host, p, "")
if test.health == probe.Unknown && err == nil {
t.Errorf("Expected error")
}