- Add tests for shell completion generation in completion_test.go - Add tests for root command execution and flags in root_test.go - Expand config tests for temperature, timeout, and log level getters - Add APIError unwrap test in errors_test.go - Add WithContext tests in logger_test.go - Stage test output artifact in .output.txt
87 lines
1.8 KiB
Go
87 lines
1.8 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")
|
|
}
|
|
}
|
|
|
|
func TestAPIErrorUnwrap(t *testing.T) {
|
|
baseErr := errors.New("base api err")
|
|
apiErr := &APIError{
|
|
StatusCode: 500,
|
|
Message: "internal error",
|
|
Err: baseErr,
|
|
}
|
|
if unwrap := apiErr.Unwrap(); unwrap != baseErr {
|
|
t.Errorf("APIError.Unwrap() = %v, want %v", unwrap, baseErr)
|
|
}
|
|
}
|