Skip to content

Commit

Permalink
handle GET requests in webhook hra (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed Mar 8, 2021
1 parent 8c0f3df commit 1753fa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controllers/horizontal_runner_autoscaler_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons
}
}()

// respond ok to GET / e.g. for health check
if r.Method == http.MethodGet {
fmt.Fprintln(w, "webhook server is running")
return
}

var payload []byte

if len(autoscaler.SecretKeyBytes) > 0 {
Expand Down
13 changes: 13 additions & 0 deletions controllers/horizontal_runner_autoscaler_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func TestWebhookPing(t *testing.T) {
)
}

func TestGetRequest(t *testing.T) {
hra := HorizontalRunnerAutoscalerGitHubWebhook{}
request, _ := http.NewRequest(http.MethodGet, "/", nil)
recorder := httptest.ResponseRecorder{}

hra.Handle(&recorder, request)
response := recorder.Result()

if response.StatusCode != http.StatusOK {
t.Errorf("want %d, got %d", http.StatusOK, response.StatusCode)
}
}

func TestGetValidCapacityReservations(t *testing.T) {
now := time.Now()

Expand Down

0 comments on commit 1753fa3

Please sign in to comment.