From 9c12e879c5d6833ce50f5b6d646ccce03a78db31 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 20 Jul 2025 23:10:50 +0300 Subject: test: add comprehensive test coverage for refactored packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/models/lister_test.go | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/models/lister_test.go (limited to 'internal/models') 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) + } +} -- cgit v1.2.3