Skip to content

Commit

Permalink
feat: Add support to use ETag for conditional requests against the Gi…
Browse files Browse the repository at this point in the history
…thub API

Signed-off-by: andrewhibbert <[email protected]>
  • Loading branch information
andrewhibbert committed Feb 6, 2025
1 parent 5f42fa6 commit ad0c43c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/scalers/github_runner_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ func apiStubHandlerCustomJob(hasRateLeft bool, exceeds30Repos bool, jobResponse
w.WriteHeader(http.StatusForbidden)
}
if strings.HasSuffix(r.URL.String(), "jobs") {
// nosemgrep: no-direct-write-to-responsewriter
_, _ = w.Write([]byte(jobResponse))
w.WriteHeader(http.StatusOK)
}
if strings.HasSuffix(r.URL.String(), "runs") {
if strings.Contains(r.URL.String(), "BadRepo") {
w.WriteHeader(http.StatusNotFound)
} else {
// nosemgrep: no-direct-write-to-responsewriter
_, _ = w.Write(buildQueueJSON())
w.WriteHeader(http.StatusOK)
}
Expand All @@ -221,6 +223,7 @@ func apiStubHandlerCustomJob(hasRateLeft bool, exceeds30Repos bool, jobResponse
}
w.WriteHeader(http.StatusOK)
} else {
// nosemgrep: no-direct-write-to-responsewriter
_, _ = w.Write([]byte(testGhUserReposResponse))
w.WriteHeader(http.StatusOK)
}
Expand All @@ -231,13 +234,15 @@ func apiStubHandlerCustomJob(hasRateLeft bool, exceeds30Repos bool, jobResponse
func apiStubHandler404() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
// nosemgrep: no-direct-write-to-responsewriter
_, _ = w.Write([]byte("not found"))
}))
}

func apiStubHandler304() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotModified)
// nosemgrep: no-direct-write-to-responsewriter
_, _ = w.Write([]byte{})
}))
}
Expand Down

0 comments on commit ad0c43c

Please sign in to comment.