diff options
author | Charlie Lukman <lukman.charlie@gmail.com> | 2021-03-31 08:36:51 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-30 20:36:51 -0500 |
commit | 512b657a42880af87e9f0d863aa6dccf3540d4ba (patch) | |
tree | 775f232676b6e1b16923f2360016237224b5bedd | |
parent | bfb86fa49a73e4194d93bea18d7acfe3694438ce (diff) | |
download | google-uuid-512b657a42880af87e9f0d863aa6dccf3540d4ba.tar.gz |
feat: add public matcher function for custom error type invalidLengthError (#78)
-rw-r--r-- | uuid.go | 6 | ||||
-rw-r--r-- | uuid_test.go | 7 |
2 files changed, 13 insertions, 0 deletions
@@ -41,6 +41,12 @@ func (err invalidLengthError) Error() string { return fmt.Sprintf("invalid UUID length: %d", err.len) } +// IsInvalidLengthError is matcher function for custom error invalidLengthError +func IsInvalidLengthError(err error) bool { + _, ok := err.(invalidLengthError) + return ok +} + // Parse decodes s into a UUID or returns an error. Both the standard UUID // forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the diff --git a/uuid_test.go b/uuid_test.go index 709e34c..99f0bed 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -526,6 +526,13 @@ func TestWrongLength(t *testing.T) { } } +func TestIsWrongLength(t *testing.T) { + _, err := Parse("12345") + if !IsInvalidLengthError(err) { + t.Errorf("expected error type is invalidLengthError") + } +} + var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479" var asBytes = []byte(asString) |