- 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
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package errors
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestGitError(t *testing.T) {
|
|
baseErr := errors.New("command failed")
|
|
gitErr := &GitError{
|
|
Command: "status",
|
|
Err: baseErr,
|
|
}
|
|
|
|
expected := "git status failed: command failed"
|
|
if gitErr.Error() != expected {
|
|
t.Errorf("GitError.Error() = %q, want %q", gitErr.Error(), expected)
|
|
}
|
|
|
|
if gitErr.Unwrap() != baseErr {
|
|
t.Errorf("GitError.Unwrap() did not return base error")
|
|
}
|
|
}
|
|
|
|
func TestAPIError(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
apiErr *APIError
|
|
expected string
|
|
shouldWrap bool
|
|
}{
|
|
{
|
|
name: "with status code",
|
|
apiErr: &APIError{
|
|
StatusCode: 404,
|
|
Message: "not found",
|
|
},
|
|
expected: "API error (status 404): not found",
|
|
},
|
|
{
|
|
name: "without status code",
|
|
apiErr: &APIError{
|
|
Message: "connection failed",
|
|
},
|
|
expected: "API error: connection failed",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.apiErr.Error() != tt.expected {
|
|
t.Errorf("APIError.Error() = %q, want %q", tt.apiErr.Error(), tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFileError(t *testing.T) {
|
|
baseErr := errors.New("permission denied")
|
|
fileErr := &FileError{
|
|
Path: "/tmp/test.txt",
|
|
Op: "read",
|
|
Err: baseErr,
|
|
}
|
|
|
|
expected := "file read failed for /tmp/test.txt: permission denied"
|
|
if fileErr.Error() != expected {
|
|
t.Errorf("FileError.Error() = %q, want %q", fileErr.Error(), expected)
|
|
}
|
|
|
|
if fileErr.Unwrap() != baseErr {
|
|
t.Errorf("FileError.Unwrap() did not return base error")
|
|
}
|
|
}
|