diff --git a/internal/core/ebook_test.go b/internal/core/ebook_test.go index e62c4b418..84df3a2fc 100644 --- a/internal/core/ebook_test.go +++ b/internal/core/ebook_test.go @@ -23,7 +23,7 @@ func TestGenerateEbook(t *testing.T) { t.Run("Successful ebook generate", func(t *testing.T) { t.Run("valid bookmarkId that return HasEbook true", func(t *testing.T) { dstFile := "/ebook/1.epub" - temp := "/tmp/tempdir" + temp := t.TempDir() deps.Domains.Storage = domains.NewStorageDomain(deps, afero.NewBasePathFs(afero.NewOsFs(), temp)) @@ -45,7 +45,7 @@ func TestGenerateEbook(t *testing.T) { t.Run("ebook generate with valid BookmarkID EbookExist ImagePathExist ReturnWithHasEbookTrue", func(t *testing.T) { //dstDir := "/ebook/2" dstFile := "/ebook/2.epub" - temp := "/tmp/tempdir" + temp := t.TempDir() deps.Domains.Storage = domains.NewStorageDomain(deps, afero.NewBasePathFs(afero.NewOsFs(), temp)) @@ -78,7 +78,7 @@ func TestGenerateEbook(t *testing.T) { }) t.Run("generate ebook valid BookmarkID EbookExist ReturnHasArchiveTrue", func(t *testing.T) { dstFile := "/ebook/3.epub" - temp := "/tmp/tempdir" + temp := t.TempDir() deps.Domains.Storage = domains.NewStorageDomain(deps, afero.NewBasePathFs(afero.NewOsFs(), temp)) @@ -109,7 +109,7 @@ func TestGenerateEbook(t *testing.T) { t.Run("specific ebook generate case", func(t *testing.T) { t.Run("invalid bookmarkId that return Error", func(t *testing.T) { dstFile := "/ebook/0.epub" - temp := "/temp/tempdir" + temp := t.TempDir() mockRequest := core.ProcessRequest{ Bookmark: model.BookmarkDTO{ ID: 0, @@ -130,7 +130,7 @@ func TestGenerateEbook(t *testing.T) { }) t.Run("ebook exist return HasEbook true", func(t *testing.T) { dstFile := "/ebook/1.epub" - temp := "/tmp/tempdir" + temp := t.TempDir() deps.Domains.Storage = domains.NewStorageDomain(deps, afero.NewBasePathFs(afero.NewOsFs(), temp)) @@ -160,7 +160,7 @@ func TestGenerateEbook(t *testing.T) { }) t.Run("generate ebook valid BookmarkID RetuenError for PDF file", func(t *testing.T) { dstFile := "/ebook/1.epub" - temp := "/tmp/tempdir" + temp := t.TempDir() mockRequest := core.ProcessRequest{ Bookmark: model.BookmarkDTO{ diff --git a/internal/core/processing_test.go b/internal/core/processing_test.go index 549e38e3c..87f23d7ea 100644 --- a/internal/core/processing_test.go +++ b/internal/core/processing_test.go @@ -22,7 +22,8 @@ func TestDownloadBookImage(t *testing.T) { t.Run("fails", func(t *testing.T) { // images is too small with unsupported format with a valid URL imageURL := "https://github.com/go-shiori/shiori/blob/master/internal/view/assets/res/apple-touch-icon-152x152.png" - dstFile := "tempDir/image.png" + temp := t.TempDir() + dstFile := temp + "/image.png" // Act err := core.DownloadBookImage(deps, imageURL, dstFile) @@ -70,6 +71,7 @@ func TestProcessBookmark(t *testing.T) { _, deps := testutil.GetTestConfigurationAndDependencies(t, context.TODO(), logger) t.Run("ProcessRequest with sucssesful result", func(t *testing.T) { + temp := t.TempDir() t.Run("Normal without image", func(t *testing.T) { bookmark := model.BookmarkDTO{ ID: 1, @@ -84,7 +86,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, } @@ -104,7 +106,7 @@ func TestProcessBookmark(t *testing.T) { } }) t.Run("Normal with multipleimage", func(t *testing.T) { - + temp := t.TempDir() html := `html @@ -128,7 +130,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, } @@ -148,6 +150,7 @@ func TestProcessBookmark(t *testing.T) { } }) t.Run("ProcessRequest sucssesful with multipleimage included favicon and Thumbnail ", func(t *testing.T) { + temp := t.TempDir() // create a file server handler for the 'testdata' directory fs := http.FileServer(http.Dir("../../testdata/")) @@ -178,7 +181,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, } @@ -198,6 +201,7 @@ func TestProcessBookmark(t *testing.T) { } }) t.Run("ProcessRequest sucssesful with empty title ", func(t *testing.T) { + temp := t.TempDir() bookmark := model.BookmarkDTO{ ID: 1, URL: "https://example.com", @@ -211,7 +215,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, } @@ -231,6 +235,7 @@ func TestProcessBookmark(t *testing.T) { } }) t.Run("ProcessRequest sucssesful with empty Excerpt", func(t *testing.T) { + temp := t.TempDir() bookmark := model.BookmarkDTO{ ID: 1, URL: "https://example.com", @@ -244,7 +249,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: false, } @@ -264,6 +269,7 @@ func TestProcessBookmark(t *testing.T) { } }) t.Run("Specific case", func(t *testing.T) { + temp := t.TempDir() t.Run("ProcessRequest with ID zero", func(t *testing.T) { bookmark := model.BookmarkDTO{ @@ -279,7 +285,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "text/html", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, } @@ -290,7 +296,7 @@ func TestProcessBookmark(t *testing.T) { }) t.Run("ProcessRequest that content type not zero", func(t *testing.T) { - + temp := t.TempDir() bookmark := model.BookmarkDTO{ ID: 1, URL: "https://example.com", @@ -304,7 +310,7 @@ func TestProcessBookmark(t *testing.T) { Bookmark: bookmark, Content: content, ContentType: "application/pdf", - DataDir: "/tmp", + DataDir: temp, KeepTitle: true, KeepExcerpt: true, }