Refactor caching functions and simplify response serialization
All checks were successful
Release Tag / release (push) Successful in 27s

- Updated the `downloadThroughCache` function to remove the upstream URL parameter, streamlining the caching process.
- Modified the `serializeRawResponse` function to eliminate unnecessary parameters, enhancing clarity and usability.
- Adjusted integration tests to align with the new function signatures, ensuring consistent testing of caching behavior.
This commit is contained in:
2025-09-21 22:55:49 -05:00
parent 45ae234694
commit 46495dc3aa
2 changed files with 5 additions and 306 deletions

View File

@@ -52,7 +52,7 @@ func testSteamURL(t *testing.T, urlPath string) {
directResp, directBody := downloadDirectly(t, steamURL)
// Test download through SteamCache
cacheResp, cacheBody := downloadThroughCache(t, sc, steamURL, urlPath)
cacheResp, cacheBody := downloadThroughCache(t, sc, urlPath)
// Compare responses
compareResponses(t, directResp, directBody, cacheResp, cacheBody, urlPath)
@@ -83,7 +83,7 @@ func downloadDirectly(t *testing.T, url string) (*http.Response, []byte) {
return resp, body
}
func downloadThroughCache(t *testing.T, sc *SteamCache, upstreamURL, urlPath string) (*http.Response, []byte) {
func downloadThroughCache(t *testing.T, sc *SteamCache, urlPath string) (*http.Response, []byte) {
// Create a test server for SteamCache
cacheServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// For real Steam URLs, we need to set the upstream to the Steam hostname
@@ -235,7 +235,7 @@ func TestCacheFileFormat(t *testing.T) {
rawResponse := sc.reconstructRawResponse(resp, bodyData)
// Serialize to cache format
cacheData, err := serializeRawResponse("/test/format", rawResponse, contentHash, "sha256")
cacheData, err := serializeRawResponse(rawResponse)
if err != nil {
t.Fatalf("Failed to serialize cache file: %v", err)
}