Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trojan295 committed Sep 18, 2024
1 parent cc9d37a commit f26d3f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions internal/healthz/healthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,34 @@ func NewServer(log *logrus.Logger) *Server {
func (hc *Server) Run(addr string) error {
mux := http.NewServeMux()

mux.HandleFunc("/healthz", hc.healthCheck)
mux.HandleFunc("/readyz", hc.readyCheck)
mux.HandleFunc("/livez", hc.liveCheck)

return http.ListenAndServe(addr, mux)
}

func (hc *Server) healthCheck(w http.ResponseWriter, r *http.Request) {
func (hc *Server) readyCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "application/json")

response := map[string]string{
"status": "ok",
}

body, err := json.Marshal(response)
if err != nil {
hc.log.WithError(err).Errorf("Failed to marshal readiness check response")
w.WriteHeader(http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)

if _, err := w.Write(body); err != nil {
hc.log.WithError(err).Errorf("Failed to write response body")
}
}

func (hc *Server) liveCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "application/json")

response := map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion internal/proxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestClient_run(t *testing.T) {
m.EXPECT().Context().Return(context.Background()).AnyTimes() // expected 0 or 1 times
},
},
wantLastSeenUpdated: false,
wantLastSeenUpdated: true,
wantErr: true,
},
{
Expand Down

0 comments on commit f26d3f1

Please sign in to comment.