Files
promptkit/internal/usecase/operation_error_test.go

35 lines
1.1 KiB
Go
Raw Normal View History

package usecase
import (
"errors"
"fmt"
"testing"
"go.maximumdirect.net/promptkit/internal/profile"
"go.maximumdirect.net/promptkit/internal/promptdef"
)
func TestOperationErrorRetainsOwnerAndCause(t *testing.T) {
cause := fmt.Errorf("nested: %w", promptdef.ErrPromptDefinitionNotFound)
outer := &OperationError{Category: ErrLLMGenerate, Cause: cause}
if !errors.Is(outer, ErrLLMGenerate) || !errors.Is(outer, promptdef.ErrPromptDefinitionNotFound) || errors.Unwrap(outer) != cause {
t.Fatalf("operation error = %v", outer)
}
for _, test := range []struct {
err error
category error
}{
{promptLookupError(cause), promptdef.ErrPromptDefinitionNotFound},
{profileLookupError(profile.ErrProfileNotFound), profile.ErrProfileNotFound},
{promptLookupError(contextFailure), ErrPromptLoad},
{profileLookupError(contextFailure), ErrProfileLoad},
} {
var operation *OperationError
if !errors.As(test.err, &operation) || operation.Category != test.category {
t.Errorf("operation = %+v", operation)
}
}
}
var contextFailure = errors.New("lookup failed")