Added test for probes ServeMux

pull/777/head
Aaron Schlesinger 9 years ago
parent ada108126c
commit fe3afa8012

@ -12,9 +12,9 @@ func livenessProbe(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func runProbesServer(addr string) error {
func newProbesMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/readiness", readinessProbe)
mux.HandleFunc("/liveness", livenessProbe)
return http.ListenAndServe(addr, mux)
return mux
}

@ -0,0 +1,28 @@
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestProbesServer(t *testing.T) {
mux := newProbesMux()
srv := httptest.NewServer(mux)
defer srv.Close()
resp, err := http.Get("/readiness")
if err != nil {
t.Fatalf("GET /readiness returned an error (%s)", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("GET /readiness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
}
resp, err = http.Get("/liveness")
if err != nil {
t.Fatalf("GET /liveness returned an error (%s)", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("GET /liveness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
}
}

@ -3,6 +3,7 @@ package main
import (
"fmt"
"net"
"net/http"
"os"
"github.com/kubernetes/helm/cmd/tiller/environment"
@ -65,7 +66,8 @@ func start(c *cobra.Command, args []string) {
}()
go func() {
if err := runProbesServer(probe); err != nil {
mux := newProbesMux()
if err := http.ListenAndServe(addr, mux); err != nil {
probeErrCh <- err
}
}()

Loading…
Cancel
Save