Files
Roberto Jiménez Sánchez 047499a363 Provisioning: introduce concept of provisioning extras (#104981)
* Spike: Extras

* Attempt to wire it up

* Hack

* Fix issue with jobs

* Wire more things up

* Fix more wiring stuff

* Remove webhook secret key from main registration

* Move secret encryption also outside register

* Add TODOs in code

* Add more explanations

* Move connectors to different package

* Move pull request job into webhooks

* Separate registration

* Remove duplicate files

* Fix missing function

* Extract webhook repository logic out of the core github repository

* Use status patcher in webhook connector

* Fix change in go mod

* Change hooks signature

* Remove TODOs

* Remove Webhook methos from go-git

* Remove leftover

* Fix mistake in OpenAPI spec

* Fix some tests

* Fix some issues

* Fix linting
2025-05-13 09:50:43 +02:00

49 lines
1016 B
Go

package provisioning
import (
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestWithTimeout(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
select {
case <-r.Context().Done():
w.WriteHeader(http.StatusGatewayTimeout)
case <-time.After(50 * time.Millisecond):
w.WriteHeader(http.StatusOK)
}
})
tests := []struct {
name string
timeout time.Duration
wantStatus int
}{
{
name: "request completes",
timeout: 100 * time.Millisecond,
wantStatus: http.StatusOK,
},
{
name: "request times out",
timeout: 10 * time.Millisecond,
wantStatus: http.StatusGatewayTimeout,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/", nil)
WithTimeout(handler, tt.timeout).ServeHTTP(w, r)
if w.Code != tt.wantStatus {
t.Errorf("withTimeout() status = %v, want %v", w.Code, tt.wantStatus)
}
})
}
}