mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 03:14:06 -05:00
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
966 B
Go
41 lines
966 B
Go
package exitcodes
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestExitError_Error(t *testing.T) {
|
|
e := New(NotConfigured, "not configured")
|
|
if e.Error() != "not configured" {
|
|
t.Fatalf("expected 'not configured', got %q", e.Error())
|
|
}
|
|
if e.Code != NotConfigured {
|
|
t.Fatalf("expected code %d, got %d", NotConfigured, e.Code)
|
|
}
|
|
}
|
|
|
|
func TestExitError_Newf(t *testing.T) {
|
|
e := Newf(Unreachable, "cannot reach %s", "server")
|
|
if e.Error() != "cannot reach server" {
|
|
t.Fatalf("expected 'cannot reach server', got %q", e.Error())
|
|
}
|
|
if e.Code != Unreachable {
|
|
t.Fatalf("expected code %d, got %d", Unreachable, e.Code)
|
|
}
|
|
}
|
|
|
|
func TestExitError_ErrorsAs(t *testing.T) {
|
|
e := New(BadRequest, "bad input")
|
|
wrapped := fmt.Errorf("wrapper: %w", e)
|
|
|
|
var exitErr *ExitError
|
|
if !errors.As(wrapped, &exitErr) {
|
|
t.Fatal("errors.As should find ExitError")
|
|
}
|
|
if exitErr.Code != BadRequest {
|
|
t.Fatalf("expected code %d, got %d", BadRequest, exitErr.Code)
|
|
}
|
|
}
|