MCPcopy
hub / github.com/gofrs/uuid / TestIsAsError

Function TestIsAsError

error_test.go:10–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestIsAsError(t *testing.T) {
11 tcs := []struct {
12 err error
13 expected string
14 expectedErr error
15 }{
16 {
17 err: fmt.Errorf("%w sample error: %v", ErrInvalidVersion, 123),
18 expected: "uuid: sample error: 123",
19 expectedErr: ErrInvalidVersion,
20 },
21 {
22 err: fmt.Errorf("%w", ErrInvalidFormat),
23 expected: "uuid: invalid UUID format",
24 expectedErr: ErrInvalidFormat,
25 },
26 {
27 err: fmt.Errorf("%w %q", ErrIncorrectFormatInString, "test"),
28 expected: "uuid: incorrect UUID format in string \"test\"",
29 expectedErr: ErrIncorrectFormatInString,
30 },
31 }
32 for i, tc := range tcs {
33 t.Run(fmt.Sprintf("Test case %d", i), func(t *testing.T) {
34 if tc.err.Error() != tc.expected {
35 t.Errorf("expected err.Error() to be '%s' but was '%s'", tc.expected, tc.err.Error())
36 }
37 var uuidErr Error
38 if !errors.As(tc.err, &uuidErr) {
39 t.Error("expected errors.As() to work")
40 }
41 if !errors.Is(tc.err, tc.expectedErr) {
42 t.Errorf("expected error to be, or wrap, the %v sentinel error", tc.expectedErr)
43 }
44 })
45 }
46}
47
48func TestParseErrors(t *testing.T) {
49 tcs := []struct {

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected