diff --git a/epub_test.go b/epub_test.go
index dd34f1b..3902b37 100644
--- a/epub_test.go
+++ b/epub_test.go
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
"net/http"
"os"
"os/exec"
@@ -18,6 +17,7 @@ import (
"github.com/bmaupin/go-epub/internal/storage"
"github.com/gofrs/uuid"
+ "github.com/stretchr/testify/require"
)
const (
@@ -59,16 +59,16 @@ const (
testFontFromFileSource = "testdata/redacted-script-regular.ttf"
testIdentifierTemplate = `%s`
testImageFromFileFilename = "testfromfile.png"
- testImageFromFileSource = "testdata/gophercolor16x16.png"
+ testImageFromFileSource = "testdata/sample.png"
testNumberFilenameStart = "01filenametest.png"
testSpaceInFilename = "filename with space.png"
- testImageFromURLSource = "https://golang.org/doc/gopher/gophercolor16x16.png"
+ testImageFromURLSource = "https://file-examples.com/storage/fe072e668b64cd6ce9c9963/2017/10/file_example_PNG_1MB.png"
testVideoFromFileFilename = "testfromfile.mp4"
testVideoFromFileSource = "testdata/sample_640x360.mp4"
- testVideoFromURLSource = "https://filesamples.com/samples/video/mp4/sample_640x360.mp4"
+ testVideoFromURLSource = "https://file-examples.com/storage/fe072e668b64cd6ce9c9963/2017/04/file_example_MP4_640_3MG.mp4"
testAudioFromFileFilename = "sample_audio.wav"
testAudioFromFileSource = "testdata/sample_audio.wav"
- testAudioFromURLSource = "https://file-examples.com/storage/fe644084cb644d3709528c4/2017/11/file_example_WAV_1MG.wav"
+ testAudioFromURLSource = "https://file-examples.com/storage/fe072e668b64cd6ce9c9963/2017/11/file_example_WAV_1MG.wav"
testLangTemplate = `%s`
testDescTemplate = `%s`
testPpdTemplate = `page-progression-direction="%s"`
@@ -293,7 +293,7 @@ func TestAddImage(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error response from test image URL: %s", err)
}
- testImageContents, err = ioutil.ReadAll(resp.Body)
+ testImageContents, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Unexpected error reading test image file from URL: %s", err)
}
@@ -343,7 +343,7 @@ func TestAddVideo(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error response from test video URL: %s", err)
}
- testVideoContents, err = ioutil.ReadAll(resp.Body)
+ testVideoContents, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Unexpected error reading test video file from URL: %s", err)
}
@@ -393,7 +393,7 @@ func TestAddAudio(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error response from test audio URL: %s", err)
}
- testAudioContents, err = ioutil.ReadAll(resp.Body)
+ testAudioContents, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Unexpected error reading test audio file from URL: %s", err)
}
@@ -751,21 +751,27 @@ func TestSetCover(t *testing.T) {
}
func TestManifestItems(t *testing.T) {
- testManifestItems := []string{`id="filenamewithspace.png" href="images/filename with space.png" media-type="image/png">`,
- `id="gophercolor16x16.png" href="images/gophercolor16x16.png" media-type="image/png">`,
+ testManifestItems := []string{
+ `id="file_example_PNG_1MB.png" href="images/file_example_PNG_1MB.png" media-type="image/png">`,
+ `id="filenamewithspace.png" href="images/filename with space.png" media-type="image/png">`,
`id="id01filenametest.png" href="images/01filenametest.png" media-type="image/png">`,
- `id="image0005.png" href="images/image0005.png" media-type="image/png">`,
`id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav">`,
+ `id="sample.png" href="images/sample.png" media-type="image/png">`,
`id="testfromfile.png" href="images/testfromfile.png" media-type="image/png">`,
}
e := NewEpub(testEpubTitle)
- e.AddImage(testImageFromFileSource, testImageFromFileFilename)
- e.AddImage(testImageFromFileSource, "")
+ _, err := e.AddImage(testImageFromFileSource, testImageFromFileFilename)
+ require.NoError(t, err)
+ _, err = e.AddImage(testImageFromFileSource, "")
+ require.NoError(t, err)
// In particular, we want to test these next two, which will be modified by fixXMLId()
- e.AddImage(testImageFromFileSource, testNumberFilenameStart)
- e.AddImage(testImageFromFileSource, testSpaceInFilename)
- e.AddImage(testImageFromURLSource, "")
+ _, err = e.AddImage(testImageFromFileSource, testNumberFilenameStart)
+ require.NoError(t, err)
+ _, err = e.AddImage(testImageFromFileSource, testSpaceInFilename)
+ require.NoError(t, err)
+ _, err = e.AddImage(testImageFromURLSource, "")
+ require.NoError(t, err)
tempDir := writeAndExtractEpub(t, e, testEpubFilename)
@@ -1000,7 +1006,7 @@ func validateEpub(t testing.TB, epubFilename string) ([]byte, error) {
t.Error("Error getting working directory")
}
- items, err := ioutil.ReadDir(cwd)
+ items, err := os.ReadDir(cwd)
if err != nil {
t.Error("Error getting contents of working directory")
}
@@ -1012,7 +1018,7 @@ func validateEpub(t testing.TB, epubFilename string) ([]byte, error) {
break
} else if strings.HasPrefix(i.Name(), testEpubcheckPrefix) {
- if i.Mode().IsDir() {
+ if i.IsDir() {
pathToEpubcheck = filepath.Join(i.Name(), testEpubcheckJarfile)
if _, err := os.Stat(pathToEpubcheck); err == nil {
break
diff --git a/go.mod b/go.mod
index 0784e70..4dba471 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,13 @@ go 1.20
require (
github.com/gabriel-vasile/mimetype v1.4.2
github.com/gofrs/uuid v4.4.0+incompatible
+ github.com/stretchr/testify v1.8.4
github.com/vincent-petithory/dataurl v1.0.0
)
-require golang.org/x/net v0.13.0 // indirect
+require (
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ golang.org/x/net v0.13.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+)
diff --git a/go.sum b/go.sum
index eb7a0c2..cf80f0d 100644
--- a/go.sum
+++ b/go.sum
@@ -1,8 +1,18 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/testdata/sample.png b/testdata/sample.png
new file mode 100644
index 0000000..e174b79
Binary files /dev/null and b/testdata/sample.png differ
diff --git a/testdata/sample_640x360.mp4 b/testdata/sample_640x360.mp4
index 5b621bd..e69de29 100644
Binary files a/testdata/sample_640x360.mp4 and b/testdata/sample_640x360.mp4 differ
diff --git a/testdata/sample_audio.wav b/testdata/sample_audio.wav
index 2ecf822..e69de29 100644
Binary files a/testdata/sample_audio.wav and b/testdata/sample_audio.wav differ
diff --git a/write_test.go b/write_test.go
index ba6a8f4..dc729a4 100644
--- a/write_test.go
+++ b/write_test.go
@@ -3,10 +3,11 @@ package epub
import (
"bytes"
"io"
- "io/ioutil"
"os"
"path/filepath"
"testing"
+
+ "github.com/stretchr/testify/require"
)
func TestEpubWriteTo(t *testing.T) {
@@ -32,7 +33,7 @@ func TestWriteToErrors(t *testing.T) {
})
t.Run("Image", func(t *testing.T) {
e := NewEpub(testEpubTitle)
- testWriteToErrors(t, e, e.AddImage, "gophercolor16x16.png")
+ testWriteToErrors(t, e, e.AddImage, "sample.png")
})
t.Run("Video", func(t *testing.T) {
e := NewEpub(testEpubTitle)
@@ -51,11 +52,12 @@ func testWriteToErrors(t *testing.T, e *Epub, adder func(string, string) (string
t.Fatalf("cannot open testdata: %v", err)
}
defer data.Close()
- temp, err := ioutil.TempFile("", "temp")
+ temp, err := os.CreateTemp("", "temp")
if err != nil {
t.Fatalf("unable to create temp file: %v", err)
}
- io.Copy(temp, data)
+ _, err = io.Copy(temp, data)
+ require.NoError(t, err)
temp.Close()
// Add temp file to epub
if _, err := adder(temp.Name(), ""); err != nil {