Handlers - Embed small HTTP test fixtures#5001
Open
amanfcp wants to merge 4 commits into
Open
Conversation
MuneebUllahKhan222
approved these changes
Jun 5, 2026
Contributor
MuneebUllahKhan222
left a comment
There was a problem hiding this comment.
LGTM! Just a couple of comments that I think we should address to make this more future-proof.
|
|
||
| // Fetched over HTTP; the ~18 MB upstream fixture would substantially grow pkg/handlers/testdata/ if embedded. | ||
| func TestHandleLargeHTTPJson(t *testing.T) { | ||
| resp, err := http.Get("https://raw.githubusercontent.com/ahrav/nothing-to-see-here/main/md_random_data.json.zip") |
Contributor
There was a problem hiding this comment.
It’s fine to fetch these files over HTTP since they are quite large to keep in the codebase. However, we should consider moving them under a repository owned by the TruffleHog org so that we still retain access to them in case the original author deletes their repository in the future.
Contributor
Author
There was a problem hiding this comment.
Great suggestion Muneeb. Thanks
|
|
||
| // Fetched over HTTP; the ~5 MB upstream fixture would notably grow pkg/handlers/testdata/ if embedded. | ||
| func TestHandleHTTPJson(t *testing.T) { | ||
| resp, err := http.Get("https://raw.githubusercontent.com/ahrav/nothing-to-see-here/main/sm_random_data.json") |
Contributor
There was a problem hiding this comment.
We should download and move this file to a repository under truffle hog's GH org.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the
// TODO: Embed a zip without making an HTTP request.at the formerpkg/handlers/handlers_test.go:42and opportunistically converts two adjacent tests that share the same upstream fixture.Embedded into
pkg/handlers/testdata/:aws-canary-creds.zipTestHandleFilesm.zipTestHandleHTTPJsonZip,BenchmarkHandleHTTPJsonZipTotal committed: ~2 MB, comparable to existing fixtures
test.debandtest.rpm(~1 MB each).Left HTTP-fetched with explanatory comments:
TestHandleHTTPJson(upstream fixture is ~5 MB)TestHandleLargeHTTPJson(upstream fixture is ~18 MB)Embedding these would notably grow
pkg/handlers/testdata/. Generating equivalent deterministic fixtures programmatically is a possible follow-up; happy to take direction from the team on which approach is preferred.Test plan
go vet ./pkg/handlers/...TestHandleFilepasses with the embedded fixtureTestHandleHTTPJsonZippasses with the embedded fixturego test ./pkg/handlers/...passes (~10 s)Checklist:
make test-community)?make lintthis requires golangci-lint)?Note
Low Risk
Test-only changes with no production handler logic modified; repo size grows by ~2 MB of committed fixtures.
Overview
Replaces remote GitHub fixtures with embedded zip bytes in
pkg/handlers/handlers_test.go, so key handler tests no longer depend on network access at runtime.//go:embedloadstestdata/aws-canary-creds.zipandtestdata/sm.zipinto package variables;TestHandleFile,TestHandleHTTPJsonZip, andBenchmarkHandleHTTPJsonZipnow feedHandleFileviabytes.NewReaderinstead ofhttp.Get. Comments document whyTestHandleHTTPJsonandTestHandleLargeHTTPJsonstill fetch larger upstream files over HTTP.Reviewed by Cursor Bugbot for commit aa6672d. Bugbot is set up for automated code reviews on this repo. Configure here.