Skip to content

Feat: Item test fixture#563

Closed
AltayAkkus wants to merge 4 commits into
internetarchive:mainfrom
AltayAkkus:feat-item-test-fixture
Closed

Feat: Item test fixture#563
AltayAkkus wants to merge 4 commits into
internetarchive:mainfrom
AltayAkkus:feat-item-test-fixture

Conversation

@AltayAkkus

Copy link
Copy Markdown
Contributor

When you want to create a models.Item for tests
previously

func setupURL(html string) *models.URL {
resp := &http.Response{
Body: io.NopCloser(bytes.NewBufferString(html)),
Header: make(http.Header),
}
resp.Header.Set("Content-Type", "text/html; charset=utf8")
newURL, err := models.NewURL("http://ex.com")
if err != nil {
panic(err)
}
newURL.SetResponse(resp)
if err := generalarchiver.ProcessBody(&newURL, false, false, 0, os.TempDir(), nil); err != nil {
panic(err)
}
return &newURL
}
func setupItem(html string) *models.Item {
newURL := setupURL(html)
return models.NewItem(newURL, "")
}
func TestHTMLOutlinks(t *testing.T) {
html := `
<html>
<head></head>
<body>
<a href="http://example.com">ex</a>
<a href="http://archive.org">ar</a>
<p>test</p>
<a href="https://web.archive.org">wa</a>
<a onclick="window.location='http://foo.com'">click me</a>
<a ondblclick="window.location='https://bar.com'">double click me</a>
<iframe title="Internet Archive" src="https://web.archive.org"></iframe>
<img src="world-map.jpg" usemap="#worldmap" alt="World Map">
<map name="worldmap">
<area shape="rect" coords="34,44,270,350" href="https://example.com/usa" alt="USA">
</map>
</body>
</html>`
URL := setupURL(html)

now

//go:embed testdata/ina_api_response.json
var inaFixture []byte

func TestExtractAssets_HydrateItemFixture(t *testing.T) {
	item := testutil.HydrateItem(t, inaFixture)
	assets, _, err := ExtractAssetsOutlinks(item)
         ...
}

You can create the JSON files by hand (look at the ina_api_response.json for ereference), define everything you need.
Or you can create them using this curl drop-in alias which just spits the JSON out.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.50%. Comparing base (aa1fbdb) to head (345e840).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
internal/pkg/postprocessor/testutil/item.go 33.33% 26 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #563      +/-   ##
==========================================
- Coverage   56.61%   56.50%   -0.11%     
==========================================
  Files         131      133       +2     
  Lines        6620     6769     +149     
==========================================
+ Hits         3748     3825      +77     
- Misses       2498     2555      +57     
- Partials      374      389      +15     
Flag Coverage Δ
e2etests 41.96% <ø> (-0.22%) ⬇️
unittests 29.28% <33.33%> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AltayAkkus

Copy link
Copy Markdown
Contributor Author

Merged into #551

@AltayAkkus AltayAkkus closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants