53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf8"
|
|
|
|
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
|
)
|
|
|
|
func TestDomainErrorMapping_HP_PROTO_09(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
retryable := map[rvboxv1.ControlError_Code]bool{
|
|
rvboxv1.ControlError_OFFLINE: true,
|
|
rvboxv1.ControlError_CAPACITY_EXHAUSTED: true,
|
|
rvboxv1.ControlError_TRANSIENT: true,
|
|
rvboxv1.ControlError_INTERNAL: true,
|
|
}
|
|
for code := rvboxv1.ControlError_Code(0); code <= rvboxv1.ControlError_CODE_ELEVATION_UNAVAILABLE; code++ {
|
|
domainErr := NewError(code, "message", "01890a5d-ac96-7a11-b234-123456789abc")
|
|
wire := domainErr.ControlError()
|
|
if wire.Code != code || wire.Message != "message" || wire.Retryable != retryable[code] || wire.IssueUuid != domainErr.IssueUUID {
|
|
t.Errorf("mapping for %s = %+v", code, wire)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDomainErrorBoundsAndCause_HP_PROTO_09(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cause := errors.New("cause")
|
|
domainErr := NewError(rvboxv1.ControlError_INTERNAL, strings.Repeat("界", MaxProtocolDetailBytes), "").WithCause(cause)
|
|
if !errors.Is(domainErr, cause) {
|
|
t.Fatal("domain error did not unwrap its cause")
|
|
}
|
|
if len(domainErr.Message) > MaxProtocolDetailBytes || !utf8.ValidString(domainErr.Message) {
|
|
t.Fatalf("bounded message has %d bytes or invalid UTF-8", len(domainErr.Message))
|
|
}
|
|
}
|
|
|
|
func TestWindowsPrelaunchErrorCodes_HP_WINCTX_01(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if got := NewExecutionContextUnavailable("normal", "").Code; got != rvboxv1.ControlError_CODE_EXECUTION_CONTEXT_UNAVAILABLE {
|
|
t.Fatalf("normal context code = %s", got)
|
|
}
|
|
if got := NewElevationUnavailable("elevated", "").Code; got != rvboxv1.ControlError_CODE_ELEVATION_UNAVAILABLE {
|
|
t.Fatalf("elevation code = %s", got)
|
|
}
|
|
}
|