Skip to content

Handlers - Embed small HTTP test fixtures#5001

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

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

Conversation

@amanfcp

@amanfcp amanfcp commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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 code paths; slightly increases repo size via committed fixtures.

Overview
Replaces network-dependent handler tests with go:embed fixtures under pkg/handlers/testdata/, so TestHandleFile, TestHandleHTTPJsonZip, and BenchmarkHandleHTTPJsonZip read from bytes.NewReader instead of http.Get.

Adds embedded aws-canary-creds.zip (~308 B) and sm.zip (~1.8 MB). TestHandleHTTPJson and TestHandleLargeHTTPJson still fetch over HTTP; comments note that embedding their ~5 MB and ~18 MB upstream assets would bloat testdata/.

Reviewed by Cursor Bugbot for commit a3891b3. 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

@MuneebUllahKhan222 MuneebUllahKhan222 left a comment

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.

LGTM! Just a couple of comments that I think we should address to make this more future-proof.

Comment thread pkg/handlers/handlers_test.go Outdated

// 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

@amanfcp amanfcp Jun 8, 2026

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.

Opened trufflesecurity/trufflehog-test-assets#1 to host these under the org. Once it merges I'll repoint the test URLs there in a small follow-up PR.

Comment thread pkg/handlers/handlers_test.go Outdated

// 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

@rosecodym rosecodym left a comment

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.

Thanks for the housekeeping!

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.

3 participants