Skip to content

Commit

Permalink
add test for file without extention and fix other test
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Feb 10, 2024
1 parent 5e94e83 commit 7080e4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion epub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,12 +1018,18 @@ func TestEmbedImage(t *testing.T) {
testSectionBodyWithImageUnvalidname := ` <h1>Section 1</h1>
<p>This is a paragraph.</p>
<p><img src="` + server.URL + `/gophercolor16x16.png?width=300" loading="lazy"/></p>`
testSectionBodyWithImageWithoutExtention := ` <h1>Section 1</h1>
<p>This is a paragraph.</p>
<p><img src="` + server.URL + `/gophercolor16x16withoutextention" loading="lazy"/></p>`
testSectionBodyWithImageExpect := ` <h1>Section 1</h1>
<p>This is a paragraph.</p>
<p><img src="../images/image0001.png" loading="lazy"/></p>`
testSectionBodyWithImageUnvalidnameExpect := ` <h1>Section 1</h1>
<p>This is a paragraph.</p>
<p><img src="../images/image0003.png" loading="lazy"/></p>`
testSectionBodyWithImageWithoutExtentionExpected := ` <h1>Section 1</h1>
<p>This is a paragraph.</p>
<p><img src="../images/image0004.png" loading="lazy"/></p>`
e, err := NewEpub(testEpubTitle)
if err != nil {
t.Error(err)
Expand All @@ -1050,6 +1056,10 @@ func TestEmbedImage(t *testing.T) {
if err != nil {
t.Errorf("Error adding section: %s", err)
}
testSection5Path, err := e.AddSection(testSectionBodyWithImageWithoutExtention, testSectionTitle, "", "")
if err != nil {
t.Errorf("Error adding section: %s", err)
}
e.EmbedImages()
tempDir := writeAndExtractEpub(t, e, testEpubFilename)

Expand Down Expand Up @@ -1109,7 +1119,21 @@ func TestEmbedImage(t *testing.T) {
"Got: %s\n"+
"Expected: %s",
contents,
testSectionContents)
testSection4Contents)
}
// test 5
contents, err = storage.ReadFile(filesystem, filepath.Join(tempDir, contentFolderName, xhtmlFolderName, testSection5Path))
if err != nil {
t.Errorf("Unexpected error reading section file: %s", err)
}
testSection5Contents := fmt.Sprintf(testSectionContentTemplate, testSectionTitle, testSectionBodyWithImageWithoutExtentionExpected)
if trimAllSpace(string(contents)) != trimAllSpace(testSection5Contents) {
t.Errorf(
"Section file contents don't match\n"+
"Got: %s\n"+
"Expected: %s",
contents,
testSection5Contents)
}
cleanup(testEpubFilename, tempDir)
}
Expand Down
Binary file added testdata/gophercolor16x16withoutextention
Binary file not shown.

0 comments on commit 7080e4d

Please sign in to comment.