mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-07-21 19:05:39 +02:00
- Use named returns for IsAlreadyConverted and WriteChapterToCBZ so errs.Capture defers propagate close errors to the caller. - Add context.Context to IsAlreadyConverted and ExtractChapter for cancellation/timeout support; thread it from Optimize. - Filter non-image files (__MACOSX, Thumbs.db, .DS_Store, etc.) and only extract supported image extensions in ExtractChapter. - Validate TempDir is non-empty in ConvertChapter before creating output dir. - Separate fatal conversion errors from PageIgnoredError in the WebP converter result aggregation so real failures aren't masked. - Fix error message "failed to load chapter" → "failed to extract chapter". - Use %w instead of %v in fmt.Errorf for proper error wrapping. - Fix LoadChapter doc comment to match its actual behavior. - Extract shared parseConvertedComment/parseConvertedCommentTime helpers to avoid duplicated zip-comment parsing logic. - Convert tests to use testify assertions (assert/require) per guidelines. Co-authored-by: Belphemur <197810+Belphemur@users.noreply.github.com>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsValidFolder(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
setup func(t *testing.T) string
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "valid directory",
|
|
setup: func(t *testing.T) string {
|
|
return t.TempDir()
|
|
},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "file not directory",
|
|
setup: func(t *testing.T) string {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "file.txt")
|
|
if err := os.WriteFile(path, []byte("content"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return path
|
|
},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "nonexistent path",
|
|
setup: func(t *testing.T) string {
|
|
return "/nonexistent/path/that/does/not/exist"
|
|
},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "empty string",
|
|
setup: func(t *testing.T) string {
|
|
return ""
|
|
},
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
path := tt.setup(t)
|
|
result := IsValidFolder(path)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|