diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-08 08:41:59 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-08 08:41:59 +0200 |
| commit | aa733f9a86b02d7b4d6edd8022a44e4ba417b24c (patch) | |
| tree | efdea87ad377557bb222e948894b5db5832ce6e9 /internal/processor/processor_test.go | |
| parent | 3a255c0c64f858d5c05797aba9a6d159b0c7d82f (diff) | |
test(task-374): fix errcheck issues in tests and support code
Diffstat (limited to 'internal/processor/processor_test.go')
| -rw-r--r-- | internal/processor/processor_test.go | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/internal/processor/processor_test.go b/internal/processor/processor_test.go index 2c8eaa6..e835681 100644 --- a/internal/processor/processor_test.go +++ b/internal/processor/processor_test.go @@ -10,8 +10,14 @@ import ( func TestNewProcessor(t *testing.T) { // Set up test environment - os.Setenv("OPENAI_API_KEY", "test-key") - defer os.Unsetenv("OPENAI_API_KEY") + if err := os.Setenv("OPENAI_API_KEY", "test-key"); err != nil { + t.Fatalf("Failed to set OPENAI_API_KEY: %v", err) + } + defer func() { + if err := os.Unsetenv("OPENAI_API_KEY"); err != nil { + t.Errorf("Failed to unset OPENAI_API_KEY: %v", err) + } + }() flags := cli.NewFlags() p := NewProcessor(flags) @@ -223,7 +229,9 @@ func TestGenerateAnkiFile(t *testing.T) { if _, err := os.Stat(csvFile); os.IsNotExist(err) { t.Error("CSV file was not created in home directory") } - os.Remove(csvFile) // Clean up + if err := os.Remove(csvFile); err != nil && !os.IsNotExist(err) { + t.Errorf("Failed to remove CSV file: %v", err) + } } func TestGenerateAnkiFile_APKG(t *testing.T) { @@ -243,9 +251,15 @@ func TestGenerateAnkiFile_APKG(t *testing.T) { p.translationCache.Add("котка", "cat") // Create dummy audio and image files - os.WriteFile(filepath.Join(word1Dir, "audio.mp3"), []byte("audio1"), 0644) - os.WriteFile(filepath.Join(word2Dir, "audio.mp3"), []byte("audio2"), 0644) - os.WriteFile(filepath.Join(word1Dir, "image.jpg"), []byte("image1"), 0644) + if err := os.WriteFile(filepath.Join(word1Dir, "audio.mp3"), []byte("audio1"), 0644); err != nil { + t.Fatalf("Failed to create test audio1 file: %v", err) + } + if err := os.WriteFile(filepath.Join(word2Dir, "audio.mp3"), []byte("audio2"), 0644); err != nil { + t.Fatalf("Failed to create test audio2 file: %v", err) + } + if err := os.WriteFile(filepath.Join(word1Dir, "image.jpg"), []byte("image1"), 0644); err != nil { + t.Fatalf("Failed to create test image file: %v", err) + } _, err := p.GenerateAnkiFile() if err != nil { @@ -264,6 +278,8 @@ func TestGenerateAnkiFile_APKG(t *testing.T) { // Clean up the created file for _, file := range files { - os.Remove(file) + if err := os.Remove(file); err != nil && !os.IsNotExist(err) { + t.Errorf("Failed to remove APKG file %s: %v", file, err) + } } } |
