mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-10-13 01:35:27 +02:00
refactor: extract base exporter, add sentinel errors, document unused fields
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Package apperrors provides sentinel errors for the articulate-parser application.
|
||||
package apperrors
|
||||
|
||||
import "errors"
|
||||
|
||||
// Export errors.
|
||||
var (
|
||||
// ErrUnsupportedFormat is returned when an unknown export format is requested.
|
||||
ErrUnsupportedFormat = errors.New("unsupported export format")
|
||||
)
|
||||
|
||||
// URI parsing errors.
|
||||
var (
|
||||
// ErrInvalidURI is returned when a URI cannot be parsed.
|
||||
ErrInvalidURI = errors.New("invalid URI")
|
||||
|
||||
// ErrInvalidDomain is returned when the URI domain is not an Articulate Rise domain.
|
||||
ErrInvalidDomain = errors.New("invalid domain for Articulate Rise URI")
|
||||
|
||||
// ErrNoShareID is returned when a share ID cannot be extracted from the URI.
|
||||
ErrNoShareID = errors.New("could not extract share ID from URI")
|
||||
)
|
||||
|
||||
// Operation errors.
|
||||
var (
|
||||
// ErrOperationCanceled is returned when an operation is canceled via context.
|
||||
ErrOperationCanceled = errors.New("operation canceled")
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
package apperrors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSentinelErrors_Unwrap(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
sentinel error
|
||||
wrapped error
|
||||
}{
|
||||
{"ErrUnsupportedFormat", ErrUnsupportedFormat, fmt.Errorf("%w: xyz", ErrUnsupportedFormat)},
|
||||
{"ErrInvalidURI", ErrInvalidURI, fmt.Errorf("%w: bad", ErrInvalidURI)},
|
||||
{"ErrInvalidDomain", ErrInvalidDomain, fmt.Errorf("%w: evil.com", ErrInvalidDomain)},
|
||||
{"ErrNoShareID", ErrNoShareID, fmt.Errorf("%w: no match", ErrNoShareID)},
|
||||
{"ErrOperationCanceled", ErrOperationCanceled, fmt.Errorf("%w: ctx done", ErrOperationCanceled)},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if !errors.Is(tt.wrapped, tt.sentinel) {
|
||||
t.Errorf("errors.Is(%v, %v) = false, want true", tt.wrapped, tt.sentinel)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSentinelErrors_Message(t *testing.T) {
|
||||
tests := []struct {
|
||||
err error
|
||||
expected string
|
||||
}{
|
||||
{ErrUnsupportedFormat, "unsupported export format"},
|
||||
{ErrInvalidURI, "invalid URI"},
|
||||
{ErrInvalidDomain, "invalid domain for Articulate Rise URI"},
|
||||
{ErrNoShareID, "could not extract share ID from URI"},
|
||||
{ErrOperationCanceled, "operation canceled"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.expected, func(t *testing.T) {
|
||||
if tt.err.Error() != tt.expected {
|
||||
t.Errorf("got %q, want %q", tt.err.Error(), tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user