From 4619e61996bfd4834b49b2723e36f49bc5d64c36 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Fri, 30 Jan 2026 16:01:36 +0100 Subject: [PATCH] test: add error path tests for marker and worker (Phase 7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit marker_test.go (+26 lines): - TestPaintSVG_InvalidTemplate: invalid Go template syntax - TestPaintPNG_InvalidImage: invalid PNG image data worker_test.go (+35 lines): - TestConvertOperation_JSONFileNotFound: missing JSON source file - TestTriggerConversion_FailedStatusUpdateError: status update failure path Coverage improvements: - conversion: 91.5% → 93.2% (TriggerConversion: 83.3% → 100%) - server: 90.3% → 90.7% (paintSVG: 83.3% → 91.7%, paintPNG: 92% → 96%) --- internal/conversion/worker_test.go | 35 ++++++++++++++++++++++++++++++ internal/server/marker_test.go | 26 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/internal/conversion/worker_test.go b/internal/conversion/worker_test.go index 9b2cab58..37894b64 100644 --- a/internal/conversion/worker_test.go +++ b/internal/conversion/worker_test.go @@ -687,3 +687,38 @@ func TestConvertOperation_InvalidStorageFormat(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "get storage engine") } + +func TestConvertOperation_JSONFileNotFound(t *testing.T) { + dir := t.TempDir() + // Don't create the JSON file - test the "file not found" error path + + repo := newErrorMockRepo() + worker := NewWorker(repo, Config{ + DataDir: dir, + }) + + ctx := context.Background() + err := worker.ConvertOne(ctx, 1, "nonexistent") + + assert.Error(t, err) + assert.Contains(t, err.Error(), "JSON file not found") +} + +func TestTriggerConversion_FailedStatusUpdateError(t *testing.T) { + dir := t.TempDir() + // Don't create the JSON file - will fail and try to update status to "failed" + + repo := newErrorMockRepo() + // Make status updates fail after the initial "converting" update + repo.updateStatusErr = fmt.Errorf("status update failed") + + worker := NewWorker(repo, Config{ + DataDir: dir, + }) + + // TriggerConversion is async, just verify it doesn't panic + worker.TriggerConversion(1, "nonexistent") + + // Give the goroutine time to run + time.Sleep(100 * time.Millisecond) +} diff --git a/internal/server/marker_test.go b/internal/server/marker_test.go index de0db48a..d739b75f 100644 --- a/internal/server/marker_test.go +++ b/internal/server/marker_test.go @@ -424,6 +424,32 @@ func TestScanDir(t *testing.T) { }) } +func TestPaintSVG_InvalidTemplate(t *testing.T) { + dir := t.TempDir() + + // Create SVG with invalid template syntax + invalidPath := filepath.Join(dir, "invalid.svg") + err := os.WriteFile(invalidPath, []byte(`{{ .Unclosed`), 0644) + require.NoError(t, err) + + c := color.RGBA{255, 0, 0, 255} + _, err = paintSVG(invalidPath, c) + assert.Error(t, err) +} + +func TestPaintPNG_InvalidImage(t *testing.T) { + dir := t.TempDir() + + // Create file with .png extension but invalid image data + invalidPath := filepath.Join(dir, "invalid.png") + err := os.WriteFile(invalidPath, []byte("not a valid png"), 0644) + require.NoError(t, err) + + c := color.RGBA{255, 0, 0, 255} + _, err = paintPNG(invalidPath, c) + assert.Error(t, err) +} + func TestMax(t *testing.T) { tests := []struct { a, b, want uint8