@@ -9,6 +9,8 @@ import ( |
| 9 | 9 | "net/http/httptest" |
| 10 | 10 | "strings" |
| 11 | 11 | "testing" |
| 12 | + |
| 13 | + "github.com/go-chi/chi/v5" |
| 12 | 14 | ) |
| 13 | 15 | |
| 14 | 16 | func TestHandlers(t *testing.T) { |
@@ -135,3 +137,43 @@ func TestHealthzHEAD(t *testing.T) { |
| 135 | 137 | t.Fatalf("HEAD /healthz: status %d, want 200", rec.Code) |
| 136 | 138 | } |
| 137 | 139 | } |
| 140 | + |
| 141 | +func TestActionsLogStreamRouteBypassesCompressAndTimeout(t *testing.T) { |
| 142 | + t.Parallel() |
| 143 | + |
| 144 | + mux := http.NewServeMux() |
| 145 | + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| 146 | + if err := Register(mux, Deps{ |
| 147 | + Logger: logger, |
| 148 | + TemplatesFS: testTemplatesFS(t), |
| 149 | + StaticFS: testStaticFS(t), |
| 150 | + LogoSVG: `<svg xmlns="http://www.w3.org/2000/svg"><title>shithub</title></svg>`, |
| 151 | + RepoActionsStreamMounter: func(r chi.Router) { |
| 152 | + r.Get("/{owner}/{repo}/actions/runs/{runIndex}/jobs/{jobIndex}/steps/{stepIndex}/log/stream", func(w http.ResponseWriter, r *http.Request) { |
| 153 | + w.Header().Set("Content-Type", "text/event-stream; charset=utf-8") |
| 154 | + if _, ok := r.Context().Deadline(); ok { |
| 155 | + _, _ = io.WriteString(w, "deadline") |
| 156 | + return |
| 157 | + } |
| 158 | + _, _ = io.WriteString(w, "no-deadline") |
| 159 | + }) |
| 160 | + }, |
| 161 | + }); err != nil { |
| 162 | + t.Fatalf("Register: %v", err) |
| 163 | + } |
| 164 | + |
| 165 | + req := httptest.NewRequest(http.MethodGet, "/octo/demo/actions/runs/1/jobs/0/steps/0/log/stream", nil) |
| 166 | + req.Header.Set("Accept-Encoding", "gzip") |
| 167 | + rec := httptest.NewRecorder() |
| 168 | + mux.ServeHTTP(rec, req) |
| 169 | + |
| 170 | + if rec.Code != http.StatusOK { |
| 171 | + t.Fatalf("status: got %d, want %d body=%q", rec.Code, http.StatusOK, rec.Body.String()) |
| 172 | + } |
| 173 | + if got := rec.Header().Get("Content-Encoding"); got != "" { |
| 174 | + t.Fatalf("Content-Encoding: got %q, want empty", got) |
| 175 | + } |
| 176 | + if got := rec.Body.String(); got != "no-deadline" { |
| 177 | + t.Fatalf("body: got %q, want no-deadline", got) |
| 178 | + } |
| 179 | +} |