diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-20 23:10:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-20 23:10:50 +0300 |
| commit | 9c12e879c5d6833ce50f5b6d646ccce03a78db31 (patch) | |
| tree | 206906b551d595b35d00586b6cc5bf9e1f3fe7f8 /internal/models | |
| parent | e580fb57a29ec3c3f3e180b20cfa6ec28687689b (diff) | |
test: add comprehensive test coverage for refactored packages
Add test suites for all newly created packages from the main.go refactoring:
- batch: 100% coverage - file reading, parsing, edge cases
- cli: 96.7% coverage - command setup, flags, configuration
- translation: 92% coverage - API integration, caching, errors
- phonetic: 87.5% coverage - API fetching, file operations
- models: 77.3% coverage - model listing functionality
- processor: 18% coverage - basic tests (limited by API dependencies)
Total: 1159 lines of test code across 7 new test files
🤖 Generated with [opencode](https://opencode.ai)
Co-Authored-By: opencode <noreply@opencode.ai>
Diffstat (limited to 'internal/models')
| -rw-r--r-- | internal/models/lister_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/models/lister_test.go b/internal/models/lister_test.go new file mode 100644 index 0000000..b125981 --- /dev/null +++ b/internal/models/lister_test.go @@ -0,0 +1,53 @@ +package models + +import ( + "os" + "testing" +) + +func TestNewLister(t *testing.T) { + lister := NewLister("test-api-key") + + if lister == nil { + t.Fatal("NewLister returned nil") + } + + if lister.apiKey != "test-api-key" { + t.Errorf("Expected API key 'test-api-key', got '%s'", lister.apiKey) + } + + if lister.client == nil { + t.Error("OpenAI client not initialized") + } +} + +func TestListAvailableModels_NoAPIKey(t *testing.T) { + lister := NewLister("") + + err := lister.ListAvailableModels() + if err == nil { + t.Error("Expected error for missing API key") + } + + expectedError := "OpenAI API key not found. Set OPENAI_API_KEY environment variable or configure in .totalrecall.yaml" + if err.Error() != expectedError { + t.Errorf("Expected error '%s', got: %v", expectedError, err) + } +} + +func TestListAvailableModels_Integration(t *testing.T) { + // Skip if no API key + apiKey := os.Getenv("OPENAI_API_KEY") + if apiKey == "" { + t.Skip("Skipping integration test: OPENAI_API_KEY not set") + } + + lister := NewLister(apiKey) + + // This test just verifies the method runs without error + // The actual output goes to stdout which we don't capture in tests + err := lister.ListAvailableModels() + if err != nil { + t.Errorf("ListAvailableModels failed: %v", err) + } +} |
