Skip to content

Commit

Permalink
update temp folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Jan 30, 2024
1 parent f71d4d2 commit 22538da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions internal/core/ebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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,
Expand All @@ -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))

Expand Down Expand Up @@ -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{
Expand Down
26 changes: 16 additions & 10 deletions internal/core/processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -84,7 +86,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand All @@ -104,7 +106,7 @@ func TestProcessBookmark(t *testing.T) {
}
})
t.Run("Normal with multipleimage", func(t *testing.T) {

temp := t.TempDir()
html := `html<html>
<head>
<meta property="og:image" content="http://example.com/image1.jpg">
Expand All @@ -128,7 +130,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand All @@ -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/"))

Expand Down Expand Up @@ -178,7 +181,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand All @@ -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",
Expand All @@ -211,7 +215,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand All @@ -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",
Expand All @@ -244,7 +249,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: false,
}
Expand All @@ -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{
Expand All @@ -279,7 +285,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "text/html",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand All @@ -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",
Expand All @@ -304,7 +310,7 @@ func TestProcessBookmark(t *testing.T) {
Bookmark: bookmark,
Content: content,
ContentType: "application/pdf",
DataDir: "/tmp",
DataDir: temp,
KeepTitle: true,
KeepExcerpt: true,
}
Expand Down

0 comments on commit 22538da

Please sign in to comment.