diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-22 07:54:57 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-22 07:54:57 +0300 |
| commit | 1cc15cfbd68d45ae6d561e5659422e72bf9ecd1d (patch) | |
| tree | 92bd29d34fed9c4d28cfe4d94e35b040c0b505bc /internal/audio/openai_provider_test.go | |
| parent | 1365dde5c25e1865b82fbfea50208327d5e3a51c (diff) | |
Remove audio cache feature to simplify codebase and avoid cache-related issues
π€ Generated with [opencode](https://opencode.ai)
Co-Authored-By: opencode <noreply@opencode.ai>
Diffstat (limited to 'internal/audio/openai_provider_test.go')
| -rw-r--r-- | internal/audio/openai_provider_test.go | 195 |
1 files changed, 2 insertions, 193 deletions
diff --git a/internal/audio/openai_provider_test.go b/internal/audio/openai_provider_test.go index 7e3f9e5..ae16ca0 100644 --- a/internal/audio/openai_provider_test.go +++ b/internal/audio/openai_provider_test.go @@ -2,8 +2,6 @@ package audio import ( "context" - "os" - "path/filepath" "strings" "testing" ) @@ -24,19 +22,9 @@ func TestNewOpenAIProvider(t *testing.T) { errMsg: "OpenAI API key is required", }, { - name: "valid config with cache", + name: "valid config", config: &Config{ - OpenAIKey: "test-key", - EnableCache: true, - CacheDir: "./test_cache", - }, - wantErr: false, - }, - { - name: "valid config without cache", - config: &Config{ - OpenAIKey: "test-key", - EnableCache: false, + OpenAIKey: "test-key", }, wantErr: false, }, @@ -52,11 +40,6 @@ func TestNewOpenAIProvider(t *testing.T) { t.Errorf("NewOpenAIProvider() error = %v, want %v", err.Error(), tt.errMsg) } - // Cleanup cache dir if created - if !tt.wantErr && tt.config.EnableCache && tt.config.CacheDir != "" { - os.RemoveAll(tt.config.CacheDir) - } - // Check provider properties if !tt.wantErr && provider != nil { if provider.Name() != "openai" { @@ -149,180 +132,6 @@ func TestPreprocessBulgarianText(t *testing.T) { } } -func TestGetCacheFilePath(t *testing.T) { - provider := &OpenAIProvider{ - config: &Config{ - OpenAIModel: "tts-1", - OpenAIVoice: "alloy", - OpenAISpeed: 1.0, - }, - cacheDir: "./test_cache", - } - - // Test basic cache path generation - path1 := provider.getCacheFilePath("ΡΠ±ΡΠ»ΠΊΠ°") - if !strings.HasPrefix(path1, "test_cache/") { - t.Errorf("Cache path should start with cache dir, got %s", path1) - } - if !strings.HasSuffix(path1, ".mp3") { - t.Errorf("Cache path should end with .mp3, got %s", path1) - } - - // Test that same input produces same path - path2 := provider.getCacheFilePath("ΡΠ±ΡΠ»ΠΊΠ°") - if path1 != path2 { - t.Errorf("Same input should produce same cache path, got %s and %s", path1, path2) - } - - // Test that different input produces different path - path3 := provider.getCacheFilePath("ΠΊΠΎΡΠΊΠ°") - if path1 == path3 { - t.Errorf("Different input should produce different cache path") - } - - // Test that different settings produce different paths - provider.config.OpenAIVoice = "nova" - path4 := provider.getCacheFilePath("ΡΠ±ΡΠ»ΠΊΠ°") - if path1 == path4 { - t.Errorf("Different voice should produce different cache path") - } - - // Test with instruction for gpt-4o-mini-tts - provider.config.OpenAIModel = "gpt-4o-mini-tts" - provider.config.OpenAIInstruction = "Test instruction" - path5 := provider.getCacheFilePath("ΡΠ±ΡΠ»ΠΊΠ°") - - provider.config.OpenAIInstruction = "Different instruction" - path6 := provider.getCacheFilePath("ΡΠ±ΡΠ»ΠΊΠ°") - if path5 == path6 { - t.Errorf("Different instruction should produce different cache path for gpt-4o-mini-tts") - } -} - -func TestCopyFile(t *testing.T) { - // Create a temporary directory for testing - tempDir := t.TempDir() - - provider := &OpenAIProvider{} - - // Create source file - srcPath := filepath.Join(tempDir, "source.txt") - srcContent := []byte("test content") - if err := os.WriteFile(srcPath, srcContent, 0644); err != nil { - t.Fatalf("Failed to create source file: %v", err) - } - - // Test copying to new file - dstPath := filepath.Join(tempDir, "dest.txt") - err := provider.copyFile(srcPath, dstPath) - if err != nil { - t.Errorf("copyFile() error = %v", err) - } - - // Verify content - dstContent, err := os.ReadFile(dstPath) - if err != nil { - t.Fatalf("Failed to read destination file: %v", err) - } - if string(dstContent) != string(srcContent) { - t.Errorf("Copied content doesn't match: got %q, want %q", dstContent, srcContent) - } - - // Test copying to subdirectory - dstPath2 := filepath.Join(tempDir, "subdir", "dest2.txt") - err = provider.copyFile(srcPath, dstPath2) - if err != nil { - t.Errorf("copyFile() to subdirectory error = %v", err) - } - - // Test copying non-existent file - err = provider.copyFile(filepath.Join(tempDir, "nonexistent.txt"), dstPath) - if err == nil { - t.Error("copyFile() expected error for non-existent source") - } -} - -func TestClearCache(t *testing.T) { - tempDir := t.TempDir() - - provider := &OpenAIProvider{ - cacheDir: filepath.Join(tempDir, "cache"), - } - - // Create cache directory with some files - os.MkdirAll(filepath.Join(provider.cacheDir, "ab"), 0755) - os.WriteFile(filepath.Join(provider.cacheDir, "ab", "test1.mp3"), []byte("data1"), 0644) - os.WriteFile(filepath.Join(provider.cacheDir, "ab", "test2.mp3"), []byte("data2"), 0644) - - // Clear cache - err := provider.ClearCache() - if err != nil { - t.Errorf("ClearCache() error = %v", err) - } - - // Verify cache directory is gone - if _, err := os.Stat(provider.cacheDir); !os.IsNotExist(err) { - t.Error("Cache directory should be removed") - } - - // Test clearing with empty cache dir - provider.cacheDir = "" - err = provider.ClearCache() - if err != nil { - t.Errorf("ClearCache() with empty dir should not error: %v", err) - } -} - -func TestGetCacheStats(t *testing.T) { - tempDir := t.TempDir() - - provider := &OpenAIProvider{ - enableCache: true, - cacheDir: filepath.Join(tempDir, "cache"), - } - - // Create the cache directory first - os.MkdirAll(provider.cacheDir, 0755) - - // Test with no cache files - count, size, err := provider.GetCacheStats() - if err != nil { - t.Errorf("GetCacheStats() error = %v", err) - } - if count != 0 || size != 0 { - t.Errorf("Expected empty cache stats, got count=%d, size=%d", count, size) - } - // Create cache files - os.MkdirAll(filepath.Join(provider.cacheDir, "ab"), 0755) - data1 := []byte("test data 1") - data2 := []byte("test data 22") - os.WriteFile(filepath.Join(provider.cacheDir, "ab", "test1.mp3"), data1, 0644) - os.WriteFile(filepath.Join(provider.cacheDir, "ab", "test2.mp3"), data2, 0644) - - // Get stats - count, size, err = provider.GetCacheStats() - if err != nil { - t.Errorf("GetCacheStats() error = %v", err) - } - if count != 2 { - t.Errorf("Expected 2 files, got %d", count) - } - expectedSize := int64(len(data1) + len(data2)) - if size != expectedSize { - t.Errorf("Expected size %d, got %d", expectedSize, size) - } - - // Test with cache disabled - provider.enableCache = false - count, size, err = provider.GetCacheStats() - if err != nil { - t.Errorf("GetCacheStats() with cache disabled error = %v", err) - } - if count != 0 || size != 0 { - t.Errorf("Expected zero stats with cache disabled, got count=%d, size=%d", count, size) - } -} - func TestGenerateAudioValidation(t *testing.T) { provider := &OpenAIProvider{ config: &Config{ |
