Commit fe3afa80 authored by Aaron Schlesinger's avatar Aaron Schlesinger

Added test for probes ServeMux

parent ada10812
......@@ -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
}
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
}
}()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment