| 1 | package uuidscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.25 errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/" |
| 6 | "netscip-go gomod github.com/golang/go/src go1.25 net/" |
| 7 | "testingscip-go gomod github.com/golang/go/src go1.25 testing/" |
| 8 | ) |
| 9 | |
| 10 | func TestIsAsErrorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestIsAsError().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 11 | tcs := []struct { |
| 12 | err error |
| 13 | expected string |
| 14 | expectedErr error |
| 15 | }{ |
| 16 | { |
| 17 | err: fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("%w sample error: %v", ErrInvalidVersionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrInvalidVersion., 123), |
| 18 | expected: "uuid: sample error: 123", |
| 19 | expectedErr: ErrInvalidVersionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrInvalidVersion., |
| 20 | }, |
| 21 | { |
| 22 | err: fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("%w", ErrInvalidFormatscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrInvalidFormat.), |
| 23 | expected: "uuid: invalid UUID format", |
| 24 | expectedErr: ErrInvalidFormatscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrInvalidFormat., |
| 25 | }, |
| 26 | { |
| 27 | err: fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("%w %q", ErrIncorrectFormatInStringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrIncorrectFormatInString., "test"), |
| 28 | expected: "uuid: incorrect UUID format in string \"test\"", |
| 29 | expectedErr: ErrIncorrectFormatInStringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrIncorrectFormatInString., |
| 30 | }, |
| 31 | } |
| 32 | for i, tc := range tcs { |
| 33 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("Test case %d", i), func(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 34 | if tc.err.Error() != tc.expected { |
| 35 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected err.Error() to be '%s' but was '%s'", tc.expected, tc.err.Error()) |
| 36 | } |
| 37 | var uuidErr Errorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Error# |
| 38 | if !errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Asscip-go gomod github.com/golang/go/src go1.25 errors/As().(tc.err, &uuidErr) { |
| 39 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected errors.As() to work") |
| 40 | } |
| 41 | if !errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Isscip-go gomod github.com/golang/go/src go1.25 errors/Is().(tc.err, tc.expectedErr) { |
| 42 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected error to be, or wrap, the %v sentinel error", tc.expectedErr) |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestParseErrorsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestParseErrors().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 49 | tcs := []struct { |
| 50 | function string |
| 51 | uuidStr string |
| 52 | expected string |
| 53 | }{ |
| 54 | { // 34 chars - With braces |
| 55 | function: "parse", |
| 56 | uuidStr: "..................................", |
| 57 | expected: "uuid: incorrect UUID format in string: invalid braces", |
| 58 | }, |
| 59 | { // 41 chars - urn:uuid: |
| 60 | function: "parse", |
| 61 | uuidStr: "123456789................................", |
| 62 | expected: "uuid: incorrect UUID format in string: invalid URN prefix", |
| 63 | }, |
| 64 | { // other |
| 65 | function: "parse", |
| 66 | uuidStr: "....", |
| 67 | expected: "uuid: incorrect UUID length", |
| 68 | }, |
| 69 | { // 36 chars - canonical, but not correct format |
| 70 | function: "parse", |
| 71 | uuidStr: "....................................", |
| 72 | expected: "uuid: incorrect UUID format in string: dashes were not in expected positions", |
| 73 | }, |
| 74 | { // 36 chars - canonical, invalid data |
| 75 | function: "parse", |
| 76 | uuidStr: "xx00ae9e-dae3-459f-ad0e-6b574be3f950", |
| 77 | expected: "uuid: invalid UUID format", |
| 78 | }, |
| 79 | { // Hash like |
| 80 | function: "parse", |
| 81 | uuidStr: "................................", |
| 82 | expected: "uuid: invalid UUID format", |
| 83 | }, |
| 84 | { // Hash like, invalid |
| 85 | function: "parse", |
| 86 | uuidStr: "xx00ae9edae3459fad0e6b574be3f950", |
| 87 | expected: "uuid: invalid UUID format", |
| 88 | }, |
| 89 | { // Hash like, invalid |
| 90 | function: "parse", |
| 91 | uuidStr: "xx00ae9edae3459fad0e6b574be3f950", |
| 92 | expected: "uuid: invalid UUID format", |
| 93 | }, |
| 94 | } |
| 95 | for i, tc := range tcs { |
| 96 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("Test case %d", i), func(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 97 | id := UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#{} |
| 98 | err := id.Parsescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Parse().(tc.uuidStr) |
| 99 | if err == nil { |
| 100 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 101 | return |
| 102 | } |
| 103 | if err.Error() != tc.expected { |
| 104 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), tc.expected) |
| 105 | } |
| 106 | err = id.UnmarshalTextscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#UnmarshalText().([]byte(tc.uuidStr)) |
| 107 | if err == nil { |
| 108 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 109 | return |
| 110 | } |
| 111 | if err.Error() != tc.expected { |
| 112 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), tc.expected) |
| 113 | } |
| 114 | }) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func TestUnmarshalBinaryErrorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestUnmarshalBinaryError().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 119 | id := UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#{} |
| 120 | b := make([]byte, 33) |
| 121 | expectedErr := "uuid: UUID must be exactly 16 bytes long" |
| 122 | err := id.UnmarshalBinaryscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#UnmarshalBinary().([]byte(b)) |
| 123 | if err == nil { |
| 124 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 125 | return |
| 126 | } |
| 127 | if err.Error() != expectedErr { |
| 128 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestScanErrorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestScanError().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 133 | id := UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#{} |
| 134 | err := id.Scanscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Scan().(123) |
| 135 | if err == nil { |
| 136 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 137 | return |
| 138 | } |
| 139 | expectedErr := "uuid: cannot convert int to UUID" |
| 140 | if err.Error() != expectedErr { |
| 141 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func TestUUIDVersionErrorsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestUUIDVersionErrors().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 146 | // UUId V1 Version |
| 147 | id := FromStringOrNilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/FromStringOrNil().("e86160d3-beff-443c-b9b5-1f8197ccb12e") |
| 148 | _, err := TimestampFromV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV1().(id) |
| 149 | if err == nil { |
| 150 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 151 | return |
| 152 | } |
| 153 | expectedErr := "uuid: e86160d3-beff-443c-b9b5-1f8197ccb12e is version 4, not version 1" |
| 154 | if err.Error() != expectedErr { |
| 155 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 156 | } |
| 157 | |
| 158 | // UUId V2 Version |
| 159 | id = FromStringOrNilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/FromStringOrNil().("e86160d3-beff-443c-b9b5-1f8197ccb12e") |
| 160 | _, err = TimestampFromV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV6().(id) |
| 161 | if err == nil { |
| 162 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 163 | return |
| 164 | } |
| 165 | expectedErr = "uuid: e86160d3-beff-443c-b9b5-1f8197ccb12e is version 4, not version 6" |
| 166 | if err.Error() != expectedErr { |
| 167 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 168 | } |
| 169 | |
| 170 | // UUId V7 Version |
| 171 | id = FromStringOrNilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/FromStringOrNil().("e86160d3-beff-443c-b9b5-1f8197ccb12e") |
| 172 | _, err = TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(id) |
| 173 | if err == nil { |
| 174 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 175 | return |
| 176 | } |
| 177 | expectedErr = "uuid: e86160d3-beff-443c-b9b5-1f8197ccb12e is version 4, not version 7" |
| 178 | if err.Error() != expectedErr { |
| 179 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // This test cannot be run in parallel with other tests since it modifies the |
| 184 | // global state |
| 185 | func TestErrNoHwAddressFoundscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestErrNoHwAddressFound().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 186 | netInterfacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/netInterfaces. = func() ([]netscip-go gomod github.com/golang/go/src go1.25 net/.Interfacescip-go gomod github.com/golang/go/src go1.25 net/Interface#, error) { |
| 187 | return nil, nil |
| 188 | } |
| 189 | defer func() { |
| 190 | netInterfacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/netInterfaces. = netscip-go gomod github.com/golang/go/src go1.25 net/.Interfacesscip-go gomod github.com/golang/go/src go1.25 net/Interfaces(). |
| 191 | }() |
| 192 | _, err := defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc().() |
| 193 | if err == nil { |
| 194 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("expected an error") |
| 195 | return |
| 196 | } |
| 197 | expectedErr := "uuid: no HW address found" |
| 198 | if err.Error() != expectedErr { |
| 199 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("unexpected error '%s' != '%s'", err.Error(), expectedErr) |
| 200 | } |
| 201 | } |