Skip to content

Handlers - Embed small HTTP test fixtures#5001

Open
amanfcp wants to merge 4 commits into
mainfrom
aman.handlers-embed-small-fixtures
Open

Handlers - Embed small HTTP test fixtures#5001
amanfcp wants to merge 4 commits into
mainfrom
aman.handlers-embed-small-fixtures

Conversation

@amanfcp
Copy link
Copy Markdown
Contributor

@amanfcp amanfcp commented Jun 1, 2026

Summary

Addresses the // TODO: Embed a zip without making an HTTP request. at the former pkg/handlers/handlers_test.go:42 and opportunistically converts two adjacent tests that share the same upstream fixture.
Embedded into pkg/handlers/testdata/:

File Size Used by
aws-canary-creds.zip 308 B TestHandleFile
sm.zip 1.8 MB TestHandleHTTPJsonZip, BenchmarkHandleHTTPJsonZip

Total committed: ~2 MB, comparable to existing fixtures test.deb and test.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/...
  • TestHandleFile passes with the embedded fixture
  • TestHandleHTTPJsonZip passes with the embedded fixture
  • Full go test ./pkg/handlers/... passes (~10 s)

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this 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:embed loads testdata/aws-canary-creds.zip and testdata/sm.zip into package variables; TestHandleFile, TestHandleHTTPJsonZip, and BenchmarkHandleHTTPJsonZip now feed HandleFile via bytes.NewReader instead of http.Get. Comments document why TestHandleHTTPJson and TestHandleLargeHTTPJson still 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.

@amanfcp amanfcp requested a review from a team June 1, 2026 13:39
@amanfcp amanfcp requested a review from a team as a code owner June 1, 2026 13:39
Copy link
Copy Markdown
Contributor

@MuneebUllahKhan222 MuneebUllahKhan222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should download and move this file to a repository under truffle hog's GH org.

@MuneebUllahKhan222 MuneebUllahKhan222 added the review/product-eng Team integrations reviewed, awaiting product-eng review label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/product-eng Team integrations reviewed, awaiting product-eng review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants