Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Aug 5, 2023
1 parent c12e3f2 commit 6296803
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/core/ebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestGenerateEbook_ValidBookmarkID_ReturnsBookmarkWithHasEbookTrue(t *testin
ContentType: "text/html",
}

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)

assert.True(t, bookmark.HasEbook)
assert.NoError(t, err)
Expand All @@ -46,7 +46,7 @@ func TestGenerateEbook_InvalidBookmarkID_ReturnsError(t *testing.T) {
ContentType: "text/html",
}

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)

assert.Equal(t, model.Bookmark{
ID: 0,
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestGenerateEbook_ValidBookmarkID_EbookExist_EbookExist_ReturnWithHasEbookT
}
defer file.Close()

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)

assert.True(t, bookmark.HasEbook)
assert.NoError(t, err)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestGenerateEbook_ValidBookmarkID_EbookExist_ImagePathExist_ReturnWithHasEb
}
defer file.Close()

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)
expectedimagePath := "/bookmark/1/thumb"
if expectedimagePath != bookmark.ImageURL {
t.Errorf("Expected imageURL %s, but got %s", bookmark.ImageURL, expectedimagePath)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestGenerateEbook_ValidBookmarkID_EbookExist_ReturnWithHasArchiveTrue(t *te
}
defer file.Close()

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)
assert.True(t, bookmark.HasArchive)
assert.NoError(t, err)
}
Expand All @@ -166,7 +166,7 @@ func TestGenerateEbook_ValidBookmarkID_RetuenError_PDF(t *testing.T) {
ContentType: "application/pdf",
}

bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)

assert.False(t, bookmark.HasEbook)
assert.Error(t, err)
Expand All @@ -175,10 +175,10 @@ func TestGenerateEbook_ValidBookmarkID_RetuenError_PDF(t *testing.T) {

func TestGenerateEbook_CreateEbookDirectoryNotWritable(t *testing.T) {
// Create a temporary directory to use as the parent directory
parentDir := t.TempDir()
tempDir := t.TempDir()

// Create a child directory with read-only permissions
ebookDir := fp.Join(parentDir, "ebook")
ebookDir := fp.Join(tempDir, "ebook")
err := os.Mkdir(ebookDir, 0444)
if err != nil {
t.Fatalf("could not create ebook directory: %s", err)
Expand All @@ -194,7 +194,7 @@ func TestGenerateEbook_CreateEbookDirectoryNotWritable(t *testing.T) {
}

// Call GenerateEbook to create the ebook directory
bookmark, err := core.GenerateEbook(mockRequest)
bookmark, err := core.GenerateEbook(mockRequest, tempDir)
if err == nil {
t.Fatal("GenerateEbook succeeded even though MkdirAll should have failed")
}
Expand Down

0 comments on commit 6296803

Please sign in to comment.