grokkit/internal/logger/logger_test.go
Greg Gauthier e355142c05 feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00

53 lines
1.1 KiB
Go

package logger
import (
"os"
"path/filepath"
"testing"
)
func TestInit(t *testing.T) {
// Create temp directory
tmpDir := t.TempDir()
oldHome := os.Getenv("HOME")
os.Setenv("HOME", tmpDir)
defer os.Setenv("HOME", oldHome)
err := Init()
if err != nil {
t.Errorf("Init() unexpected error: %v", err)
}
// Check log file was created
logFile := filepath.Join(tmpDir, ".config", "grokkit", "grokkit.log")
if _, err := os.Stat(logFile); os.IsNotExist(err) {
t.Errorf("Log file not created at %s", logFile)
}
}
func TestLogging(t *testing.T) {
tmpDir := t.TempDir()
oldHome := os.Getenv("HOME")
os.Setenv("HOME", tmpDir)
defer os.Setenv("HOME", oldHome)
if err := Init(); err != nil {
t.Fatalf("Init() failed: %v", err)
}
// These should not panic
Info("test info message")
Error("test error message")
Debug("test debug message")
// Verify log file has content
logFile := filepath.Join(tmpDir, ".config", "grokkit", "grokkit.log")
content, err := os.ReadFile(logFile)
if err != nil {
t.Errorf("Failed to read log file: %v", err)
}
if len(content) == 0 {
t.Errorf("Log file is empty")
}
}