mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 12:38:50 +02:00
test: add expectation on conversion
This commit is contained in:
@@ -17,6 +17,10 @@ func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
|||||||
|
|
||||||
// Create a new ZIP writer
|
// Create a new ZIP writer
|
||||||
zipWriter := zip.NewWriter(zipFile)
|
zipWriter := zip.NewWriter(zipFile)
|
||||||
|
err = zipWriter.SetComment("Created by CBZOptimizer")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
defer zipWriter.Close()
|
defer zipWriter.Close()
|
||||||
|
|
||||||
// Write each page to the ZIP archive
|
// Write each page to the ZIP archive
|
||||||
|
@@ -6,25 +6,51 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadChapter(t *testing.T) {
|
func TestLoadChapter(t *testing.T) {
|
||||||
// Define the path to the .cbz file
|
type testCase struct {
|
||||||
chapterFilePath := "../testdata/Chapter 1.cbz"
|
name string
|
||||||
|
filePath string
|
||||||
// Load the chapter
|
expectedPages int
|
||||||
chapter, err := LoadChapter(chapterFilePath)
|
expectedSeries string
|
||||||
if err != nil {
|
expectedConversion bool
|
||||||
t.Fatalf("Failed to load chapter: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the number of pages
|
testCases := []testCase{
|
||||||
expectedPages := 16
|
{
|
||||||
actualPages := len(chapter.Pages)
|
name: "Original Chapter",
|
||||||
if actualPages != expectedPages {
|
filePath: "../testdata/Chapter 1.cbz",
|
||||||
t.Errorf("Expected %d pages, but got %d", expectedPages, actualPages)
|
expectedPages: 16,
|
||||||
|
expectedSeries: "<Series>Boundless Necromancer</Series>",
|
||||||
|
expectedConversion: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Converted Chapter",
|
||||||
|
filePath: "../testdata/Chapter 1_converted.cbz",
|
||||||
|
expectedPages: 107,
|
||||||
|
expectedSeries: "<Series>Boundless Necromancer</Series>",
|
||||||
|
expectedConversion: true,
|
||||||
|
},
|
||||||
|
// Add more test cases as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if ComicInfoXml contains the expected series name
|
for _, tc := range testCases {
|
||||||
expectedSeries := "<Series>Boundless Necromancer</Series>"
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if !strings.Contains(chapter.ComicInfoXml, expectedSeries) {
|
chapter, err := LoadChapter(tc.filePath)
|
||||||
t.Errorf("ComicInfoXml does not contain the expected series: %s", expectedSeries)
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to load chapter: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actualPages := len(chapter.Pages)
|
||||||
|
if actualPages != tc.expectedPages {
|
||||||
|
t.Errorf("Expected %d pages, but got %d", tc.expectedPages, actualPages)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(chapter.ComicInfoXml, tc.expectedSeries) {
|
||||||
|
t.Errorf("ComicInfoXml does not contain the expected series: %s", tc.expectedSeries)
|
||||||
|
}
|
||||||
|
|
||||||
|
if chapter.IsConverted != tc.expectedConversion {
|
||||||
|
t.Errorf("Expected chapter to be converted: %t, but got %t", tc.expectedConversion, chapter.IsConverted)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
testdata/Chapter 1_converted.cbz
vendored
Normal file
BIN
testdata/Chapter 1_converted.cbz
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user