test: improve testing suite for expected failure

This commit is contained in:
Antoine Aflalo
2024-08-28 12:03:33 -04:00
parent dbf7f6c262
commit 62638517e4

View File

@@ -2,7 +2,9 @@ package converter
import ( import (
"bytes" "bytes"
"github.com/belphemur/CBZOptimizer/converter/constant"
"github.com/belphemur/CBZOptimizer/manga" "github.com/belphemur/CBZOptimizer/manga"
"golang.org/x/exp/slices"
"image" "image"
"image/jpeg" "image/jpeg"
"os" "os"
@@ -15,26 +17,31 @@ func TestConvertChapter(t *testing.T) {
name string name string
genTestChapter func(path string) (*manga.Chapter, error) genTestChapter func(path string) (*manga.Chapter, error)
split bool split bool
expectFailure []constant.ConversionFormat
}{ }{
{ {
name: "All split pages", name: "All split pages",
genTestChapter: genBigPages, genTestChapter: genBigPages,
split: true, split: true,
expectFailure: []constant.ConversionFormat{},
}, },
{ {
name: "Big Pages, no split", name: "Big Pages, no split",
genTestChapter: genBigPages, genTestChapter: genBigPages,
split: false, split: false,
expectFailure: []constant.ConversionFormat{constant.WebP},
}, },
{ {
name: "No split pages", name: "No split pages",
genTestChapter: genSmallPages, genTestChapter: genSmallPages,
split: false, split: false,
expectFailure: []constant.ConversionFormat{},
}, },
{ {
name: "Mix of split and no split pages", name: "Mix of split and no split pages",
genTestChapter: genMixSmallBig, genTestChapter: genMixSmallBig,
split: true, split: true,
expectFailure: []constant.ConversionFormat{},
}, },
} }
// Load test genTestChapter from testdata // Load test genTestChapter from testdata
@@ -63,9 +70,15 @@ func TestConvertChapter(t *testing.T) {
t.Log(msg) t.Log(msg)
} }
convertedChapter, err := converter.ConvertChapter(chapter, quality, false, progress) convertedChapter, err := converter.ConvertChapter(chapter, quality, tc.split, progress)
if err != nil { if err != nil {
if slices.Contains(tc.expectFailure, converter.Format()) {
t.Logf("Expected failure to convert genTestChapter: %v", err)
return
}
t.Fatalf("failed to convert genTestChapter: %v", err) t.Fatalf("failed to convert genTestChapter: %v", err)
} else if slices.Contains(tc.expectFailure, converter.Format()) {
t.Fatalf("expected failure to convert genTestChapter didn't happen")
} }
if len(convertedChapter.Pages) == 0 { if len(convertedChapter.Pages) == 0 {