diff --git a/tools/capver/main_test.go b/tools/capver/main_test.go index 49b7e963d..5dfc18323 100644 --- a/tools/capver/main_test.go +++ b/tools/capver/main_test.go @@ -16,7 +16,7 @@ func TestFetch(t *testing.T) { tests := []struct { name string - statuses []int // served in order; the last one repeats + statuses []int // served in order; the last one repeats; 0 drops the connection wantBody string wantErr error wantCalls int32 @@ -33,6 +33,18 @@ func TestFetch(t *testing.T) { wantBody: "body", wantCalls: 2, }, + { + name: "rate-limited-then-ok", + statuses: []int{http.StatusTooManyRequests, http.StatusOK}, + wantBody: "body", + wantCalls: 2, + }, + { + name: "dropped-connection-then-ok", + statuses: []int{0, http.StatusOK}, + wantBody: "body", + wantCalls: 2, + }, { name: "always-unavailable-fails", statuses: []int{http.StatusServiceUnavailable}, @@ -53,7 +65,13 @@ func TestFetch(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { n := int(calls.Add(1)) - 1 - w.WriteHeader(tt.statuses[min(n, len(tt.statuses)-1)]) + + status := tt.statuses[min(n, len(tt.statuses)-1)] + if status == 0 { + panic(http.ErrAbortHandler) + } + + w.WriteHeader(status) _, _ = w.Write([]byte("body")) })) defer srv.Close()