Skip to content

Commit 4063aec

Browse files
charlielukmancharlie.lukman@pinhome.id
authored andcommitted
feat: add public matcher function for custom error type invalidLengthError
1 parent bfb86fa commit 4063aec

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

uuid.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func (err invalidLengthError) Error() string {
4141
return fmt.Sprintf("invalid UUID length: %d", err.len)
4242
}
4343

44+
// IsInvalidLengthError is matcher function for custom error invalidLengthError
45+
func IsInvalidLengthError(err error) bool {
46+
_, ok := err.(invalidLengthError)
47+
return ok
48+
}
49+
4450
// Parse decodes s into a UUID or returns an error. Both the standard UUID
4551
// forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
4652
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the

uuid_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ func TestWrongLength(t *testing.T) {
526526
}
527527
}
528528

529+
func TestIsWrongLength(t *testing.T) {
530+
_, err := Parse("12345")
531+
if !IsInvalidLengthError(err) {
532+
t.Errorf("expected error type is invalidLengthError")
533+
}
534+
}
535+
529536
var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
530537
var asBytes = []byte(asString)
531538

0 commit comments

Comments
 (0)