github.com/m-lab/locate@v0.17.6/cmd/heartbeat/health/healthtest/healthtest.go (about) 1 package healthtest 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "time" 7 ) 8 9 func TestHealthServer(code int) *httptest.Server { 10 mux := http.NewServeMux() 11 mux.Handle("/health", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 12 w.WriteHeader(code) 13 })) 14 s := httptest.NewServer(mux) 15 return s 16 } 17 18 func TestTimeoutServer(timeout time.Duration) *httptest.Server { 19 mux := http.NewServeMux() 20 mux.Handle("/health", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 21 time.Sleep(timeout) 22 })) 23 s := httptest.NewServer(mux) 24 return s 25 }