diff options
author | Nick <nick.guenther@polymtl.ca> | 2023-03-15 17:51:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-15 16:51:39 -0500 |
commit | 6aef9e0a2f7df03893f00a657749b29e11ed839e (patch) | |
tree | 76478e021554897ca804e39c1d37e53ef0d06574 /tests | |
parent | 19cbd5c3d9893647d85f7fc5b873059d1d6d436d (diff) | |
download | gitea-6aef9e0a2f7df03893f00a657749b29e11ed839e.tar.gz gitea-6aef9e0a2f7df03893f00a657749b29e11ed839e.zip |
Replace `repo.namedBlob` by `git.TreeEntry`. (#22898)
`namedBlob` turned out to be a poor imitation of a `TreeEntry`. Using
the latter directly shortens this code.
This partially undoes https://github.com/go-gitea/gitea/pull/23152/,
which I found a merge conflict with, and also expands the test it added
to cover the subtle README-in-a-subfolder case.
Diffstat (limited to 'tests')
4 files changed, 35 insertions, 5 deletions
diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/16/633238d370a441f98dca532e4296a619c4c85f b/tests/gitea-repositories-meta/user2/repo1.git/objects/16/633238d370a441f98dca532e4296a619c4c85f Binary files differnew file mode 100644 index 0000000000..310f0ca77a --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo1.git/objects/16/633238d370a441f98dca532e4296a619c4c85f diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/46/49299398e4d39a5c09eb4f534df6f1e1eb87cc b/tests/gitea-repositories-meta/user2/repo1.git/objects/46/49299398e4d39a5c09eb4f534df6f1e1eb87cc new file mode 100644 index 0000000000..b32e1d2f5c --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo1.git/objects/46/49299398e4d39a5c09eb4f534df6f1e1eb87cc @@ -0,0 +1,4 @@ +xQJ0E*f>I@D_!n`L^mhS ^
e] +3wunzr,].6ԋC$uMr +1zaI\ 㘺(>T6x:Oײ|u9~l"i$c kZ[S +SC;EvM!#G30ǘy]
\ No newline at end of file diff --git a/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/sub-home-md-img-check b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/sub-home-md-img-check new file mode 100644 index 0000000000..dfe11055c1 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/sub-home-md-img-check @@ -0,0 +1 @@ +4649299398e4d39a5c09eb4f534df6f1e1eb87cc diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index cef9dccf24..40f5f56a35 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -362,7 +362,7 @@ func TestViewRepoDirectoryReadme(t *testing.T) { missing("symlink-loop", "/user2/readme-test/src/branch/symlink-loop/") } -func TestMarkDownImage(t *testing.T) { +func TestMarkDownReadmeImage(t *testing.T) { defer tests.PrepareTestEnv(t)() session := loginUser(t, "user2") @@ -371,13 +371,38 @@ func TestMarkDownImage(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - _, exists := htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src") - assert.True(t, exists, "Repo home page markdown image link check failed") + src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src") + assert.True(t, exists, "Image not found in README") + assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg") req = NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check/README.md") resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc = NewHTMLParser(t, resp.Body) - _, exists = htmlDoc.doc.Find(`img[src="/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg"]`).Attr("src") - assert.True(t, exists, "Repo src page markdown image link check failed") + src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src") + assert.True(t, exists, "Image not found in markdown file") + assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg") +} + +func TestMarkDownReadmeImageSubfolder(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + // this branch has the README in the special docs/README.md location + req := NewRequest(t, "GET", "/user2/repo1/src/branch/sub-home-md-img-check") + resp := session.MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src") + assert.True(t, exists, "Image not found in README") + assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg") + + req = NewRequest(t, "GET", "/user2/repo1/src/branch/sub-home-md-img-check/docs/README.md") + resp = session.MakeRequest(t, req, http.StatusOK) + + htmlDoc = NewHTMLParser(t, resp.Body) + src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src") + assert.True(t, exists, "Image not found in markdown file") + assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg") } |