github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekatyp/uuid_test.go (about) 1 // Copyright © 2020. All rights reserved. 2 // Refactorer, modifier: Ilya Yuryevich. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 // Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru> 7 // 8 // Permission is hereby granted, free of charge, to any person obtaining 9 // a copy of this software and associated documentation files (the 10 // "Software"), to deal in the Software without restriction, including 11 // without limitation the rights to use, copy, modify, merge, publish, 12 // distribute, sublicense, and/or sell copies of the Software, and to 13 // permit persons to whom the Software is furnished to do so, subject to 14 // the following conditions: 15 // 16 // The above copyright notice and this permission notice shall be 17 // included in all copies or substantial portions of the Software. 18 // 19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 27 package ekatyp 28 29 import ( 30 "bytes" 31 "crypto/rand" 32 "fmt" 33 "testing" 34 "testing/iotest" 35 36 "github.com/stretchr/testify/require" 37 ) 38 39 func TestFromBytes(t *testing.T) { 40 41 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 42 b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 43 44 u1, err := UUID_FromBytes(b1) 45 46 require.NoError(t, err) 47 require.Equal(t, u, u1) 48 49 b2 := []byte{} 50 _, err = UUID_FromBytes(b2) 51 52 require.Error(t, err) 53 } 54 55 func BenchmarkFromBytes(b *testing.B) { 56 b.ReportAllocs() 57 bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 58 for i := 0; i < b.N; i++ { 59 _, _ = UUID_FromBytes(bytes) 60 } 61 } 62 63 func TestMarshalBinary(t *testing.T) { 64 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 65 b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 66 67 b2, err := u.MarshalBinary() 68 69 require.NoError(t, err) 70 require.Equal(t, b1, b2) 71 } 72 73 func BenchmarkMarshalBinary(b *testing.B) { 74 b.ReportAllocs() 75 u, _ := UUID_NewV4() 76 for i := 0; i < b.N; i++ { 77 _, _ = u.MarshalBinary() 78 } 79 } 80 81 func TestUnmarshalBinary(t *testing.T) { 82 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 83 b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 84 85 u1 := UUID{} 86 err := u1.UnmarshalBinary(b1) 87 88 require.NoError(t, err) 89 require.Equal(t, u, u1) 90 91 b2 := []byte{} 92 u2 := UUID{} 93 err = u2.UnmarshalBinary(b2) 94 95 require.Error(t, err) 96 } 97 98 func TestFromString(t *testing.T) { 99 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 100 101 s1 := "6ba7b810-9dad-11d1-80b4-00c04fd430c8" 102 s2 := "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" 103 s3 := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" 104 s4 := "6ba7b8109dad11d180b400c04fd430c8" 105 s5 := "urn:uuid:6ba7b8109dad11d180b400c04fd430c8" 106 107 _, err := UUID_FromString("") 108 require.Error(t, err) 109 110 u1, err := UUID_FromString(s1) 111 require.NoError(t, err) 112 require.Equal(t, u, u1) 113 114 u2, err := UUID_FromString(s2) 115 require.NoError(t, err) 116 require.Equal(t, u, u2) 117 118 u3, err := UUID_FromString(s3) 119 require.NoError(t, err) 120 require.Equal(t, u, u3) 121 122 u4, err := UUID_FromString(s4) 123 require.NoError(t, err) 124 require.Equal(t, u, u4) 125 126 u5, err := UUID_FromString(s5) 127 require.NoError(t, err) 128 require.Equal(t, u, u5) 129 } 130 131 func BenchmarkFromString(b *testing.B) { 132 b.ReportAllocs() 133 str := "6ba7b810-9dad-11d1-80b4-00c04fd430c8" 134 for i := 0; i < b.N; i++ { 135 _, _ = UUID_FromString(str) 136 } 137 } 138 139 func BenchmarkFromStringUrn(b *testing.B) { 140 b.ReportAllocs() 141 str := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" 142 for i := 0; i < b.N; i++ { 143 _, _ = UUID_FromString(str) 144 } 145 } 146 147 func BenchmarkFromStringWithBrackets(b *testing.B) { 148 b.ReportAllocs() 149 str := "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" 150 for i := 0; i < b.N; i++ { 151 _, _ = UUID_FromString(str) 152 } 153 } 154 155 func TestFromStringShort(t *testing.T) { 156 // Invalid 35-character UUID string 157 s1 := "6ba7b810-9dad-11d1-80b4-00c04fd430c" 158 159 for i := len(s1); i >= 0; i-- { 160 _, err := UUID_FromString(s1[:i]) 161 require.Error(t, err) 162 } 163 } 164 165 func TestFromStringLong(t *testing.T) { 166 // Invalid 37+ character UUID string 167 strings := []string{ 168 "6ba7b810-9dad-11d1-80b4-00c04fd430c8=", 169 "6ba7b810-9dad-11d1-80b4-00c04fd430c8}", 170 "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}f", 171 "6ba7b810-9dad-11d1-80b4-00c04fd430c800c04fd430c8", 172 } 173 174 for _, str := range strings { 175 _, err := UUID_FromString(str) 176 require.Error(t, err) 177 } 178 } 179 180 func TestFromStringInvalid(t *testing.T) { 181 // Invalid UUID string formats 182 strings := []string{ 183 "6ba7b8109dad11d180b400c04fd430c86ba7b8109dad11d180b400c04fd430c8", 184 "urn:uuid:{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", 185 "uuid:urn:6ba7b810-9dad-11d1-80b4-00c04fd430c8", 186 "uuid:urn:6ba7b8109dad11d180b400c04fd430c8", 187 "6ba7b8109-dad-11d1-80b4-00c04fd430c8", 188 "6ba7b810-9dad1-1d1-80b4-00c04fd430c8", 189 "6ba7b810-9dad-11d18-0b4-00c04fd430c8", 190 "6ba7b810-9dad-11d1-80b40-0c04fd430c8", 191 "6ba7b810+9dad+11d1+80b4+00c04fd430c8", 192 "(6ba7b810-9dad-11d1-80b4-00c04fd430c8}", 193 "{6ba7b810-9dad-11d1-80b4-00c04fd430c8>", 194 "zba7b810-9dad-11d1-80b4-00c04fd430c8", 195 "6ba7b810-9dad11d180b400c04fd430c8", 196 "6ba7b8109dad-11d180b400c04fd430c8", 197 "6ba7b8109dad11d1-80b400c04fd430c8", 198 "6ba7b8109dad11d180b4-00c04fd430c8", 199 } 200 201 for _, str := range strings { 202 _, err := UUID_FromString(str) 203 require.Error(t, err) 204 } 205 } 206 207 func TestFromStringOrNil(t *testing.T) { 208 require.Equal(t, _UUID_NULL, UUID_FromString_OrNil("")) 209 } 210 211 func TestFromBytesOrNil(t *testing.T) { 212 require.Equal(t, _UUID_NULL, UUID_FromBytes_OrNil([]byte{})) 213 } 214 215 func TestMarshalText(t *testing.T) { 216 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 217 b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 218 219 b2, err := u.MarshalText() 220 require.NoError(t, err) 221 require.Equal(t, b1, b2) 222 } 223 224 func BenchmarkMarshalText(b *testing.B) { 225 b.ReportAllocs() 226 u, _ := UUID_NewV4() 227 for i := 0; i < b.N; i++ { 228 _, _ = u.MarshalText() 229 } 230 } 231 232 func TestUnmarshalText(t *testing.T) { 233 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 234 b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 235 236 u1 := UUID{} 237 err := u1.UnmarshalText(b1) 238 require.NoError(t, err) 239 require.Equal(t, u, u1) 240 241 b2 := []byte("") 242 u2 := UUID{} 243 err = u2.UnmarshalText(b2) 244 require.Error(t, err) 245 } 246 247 func BenchmarkUnmarshalText(b *testing.B) { 248 b.ReportAllocs() 249 bytes := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 250 u := UUID{} 251 for i := 0; i < b.N; i++ { 252 _ = u.UnmarshalText(bytes) 253 } 254 } 255 256 func BenchmarkMarshalToString(b *testing.B) { 257 b.ReportAllocs() 258 u, _ := UUID_NewV4() 259 for i := 0; i < b.N; i++ { 260 _ = u.String() 261 } 262 } 263 264 type faultyReader struct { 265 callsNum int 266 readToFail int // Read call number to fail 267 } 268 269 func (r *faultyReader) Read(dest []byte) (int, error) { 270 r.callsNum++ 271 if (r.callsNum - 1) == r.readToFail { 272 return 0, fmt.Errorf("io: reader is faulty") 273 } 274 return rand.Read(dest) 275 } 276 277 func TestNewV1(t *testing.T) { 278 u1, err := UUID_NewV1() 279 require.NoError(t, err) 280 require.Equal(t, UUID_V1, u1.Version()) 281 require.Equal(t, UUID_VARIANT_RFC4122, u1.Variant()) 282 283 u2, err := UUID_NewV1() 284 require.NoError(t, err) 285 require.Equal(t, UUID_V1, u2.Version()) 286 require.Equal(t, UUID_VARIANT_RFC4122, u2.Variant()) 287 288 require.NotEqual(t, u1, u2) 289 } 290 291 func TestNewV1FaultyRand(t *testing.T) { 292 g := newRFC4122Generator(new(faultyReader)) 293 u1, err := g.NewV1() 294 require.Error(t, err) 295 require.Equal(t, _UUID_NULL, u1) 296 } 297 298 func BenchmarkNewV1(b *testing.B) { 299 b.ReportAllocs() 300 for i := 0; i < b.N; i++ { 301 _, _ = UUID_NewV1() 302 } 303 } 304 305 func TestNewV2(t *testing.T) { 306 u1, err := UUID_NewV2(UUID_DOMAIN_PERSON) 307 require.NoError(t, err) 308 require.Equal(t, UUID_V2, u1.Version()) 309 require.Equal(t, UUID_VARIANT_RFC4122, u1.Variant()) 310 311 u2, err := UUID_NewV2(UUID_DOMAIN_GROUP) 312 require.NoError(t, err) 313 require.Equal(t, UUID_V2, u2.Version()) 314 require.Equal(t, UUID_VARIANT_RFC4122, u2.Variant()) 315 316 u3, err := UUID_NewV2(UUID_DOMAIN_ORG) 317 require.NoError(t, err) 318 require.Equal(t, UUID_V2, u3.Version()) 319 require.Equal(t, UUID_VARIANT_RFC4122, u3.Variant()) 320 } 321 322 func TestNewV2FaultyRand(t *testing.T) { 323 g := newRFC4122Generator(new(faultyReader)) 324 u1, err := g.NewV2(UUID_DOMAIN_PERSON) 325 require.Error(t, err) 326 require.Equal(t, _UUID_NULL, u1) 327 } 328 329 func BenchmarkNewV2(b *testing.B) { 330 b.ReportAllocs() 331 for i := 0; i < b.N; i++ { 332 _, _ = UUID_NewV2(UUID_DOMAIN_PERSON) 333 } 334 } 335 336 func TestNewV3(t *testing.T) { 337 u1 := UUID_NewV3(UUID_NAMESPACE_DNS, "www.example.com") 338 require.Equal(t, UUID_V3, u1.Version()) 339 require.Equal(t, UUID_VARIANT_RFC4122, u1.Variant()) 340 require.Equal(t, "5df41881-3aed-3515-88a7-2f4a814cf09e", u1.String()) 341 342 u2 := UUID_NewV3(UUID_NAMESPACE_DNS, "example.com") 343 require.NotEqual(t, u2, u1) 344 345 u3 := UUID_NewV3(UUID_NAMESPACE_DNS, "example.com") 346 require.Equal(t, u3, u2) 347 348 u4 := UUID_NewV3(UUID_NAMESPACE_URL, "example.com") 349 require.NotEqual(t, u4, u3) 350 } 351 352 func BenchmarkNewV3(b *testing.B) { 353 b.ReportAllocs() 354 for i := 0; i < b.N; i++ { 355 _ = UUID_NewV3(UUID_NAMESPACE_DNS, "www.example.com") 356 } 357 } 358 359 func TestNewV4(t *testing.T) { 360 u1, err := UUID_NewV4() 361 require.NoError(t, err) 362 require.Equal(t, UUID_V4, u1.Version()) 363 require.Equal(t, UUID_VARIANT_RFC4122, u1.Variant()) 364 365 u2, err := UUID_NewV4() 366 require.NoError(t, err) 367 require.Equal(t, UUID_V4, u2.Version()) 368 require.Equal(t, UUID_VARIANT_RFC4122, u2.Variant()) 369 370 require.NotEqual(t, u2, u1) 371 } 372 373 func TestNewV4FaultyRand(t *testing.T) { 374 g := newRFC4122Generator(new(faultyReader)) 375 u1, err := g.NewV4() 376 require.Error(t, err) 377 require.Equal(t, _UUID_NULL, u1) 378 } 379 380 func TestNewV4PartialRead(t *testing.T) { 381 g := newRFC4122Generator(iotest.OneByteReader(rand.Reader)) 382 u1, err := g.NewV4() 383 zeros := bytes.Count(u1.Bytes(), []byte{0}) 384 mostlyZeros := zeros >= 10 385 386 require.NoError(t, err) 387 require.False(t, mostlyZeros) 388 } 389 390 func BenchmarkNewV4(b *testing.B) { 391 b.ReportAllocs() 392 for i := 0; i < b.N; i++ { 393 _, _ = UUID_NewV4() 394 } 395 } 396 397 func TestNewV5(t *testing.T) { 398 u1 := UUID_NewV5(UUID_NAMESPACE_DNS, "www.example.com") 399 require.Equal(t, UUID_V5, u1.Version()) 400 require.Equal(t, UUID_VARIANT_RFC4122, u1.Variant()) 401 require.Equal(t, "2ed6657d-e927-568b-95e1-2665a8aea6a2", u1.String()) 402 403 u2 := UUID_NewV5(UUID_NAMESPACE_DNS, "example.com") 404 require.NotEqual(t, u2, u1) 405 406 u3 := UUID_NewV5(UUID_NAMESPACE_DNS, "example.com") 407 require.Equal(t, u3, u2) 408 409 u4 := UUID_NewV5(UUID_NAMESPACE_URL, "example.com") 410 require.NotEqual(t, u4, u3) 411 } 412 413 func BenchmarkNewV5(b *testing.B) { 414 b.ReportAllocs() 415 for i := 0; i < b.N; i++ { 416 _ = UUID_NewV5(UUID_NAMESPACE_DNS, "www.example.com") 417 } 418 } 419 420 func TestValue(t *testing.T) { 421 u, err := UUID_FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 422 require.NoError(t, err) 423 424 val, err := u.Value() 425 require.NoError(t, err) 426 require.Equal(t, u.String(), val) 427 } 428 429 func TestValueNil(t *testing.T) { 430 u := UUID{} 431 432 val, err := u.Value() 433 require.NoError(t, err) 434 require.Equal(t, nil, val) 435 } 436 437 func TestScanBinary(t *testing.T) { 438 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 439 b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 440 441 u1 := UUID{} 442 err := u1.Scan(b1) 443 require.NoError(t, err) 444 require.Equal(t, u, u1) 445 446 b2 := []byte{} 447 u2 := UUID{} 448 449 err = u2.Scan(b2) 450 require.Error(t, err) 451 } 452 453 func TestScanString(t *testing.T) { 454 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 455 s1 := "6ba7b810-9dad-11d1-80b4-00c04fd430c8" 456 457 u1 := UUID{} 458 err := u1.Scan(s1) 459 require.NoError(t, err) 460 require.Equal(t, u, u1) 461 462 s2 := "" 463 u2 := UUID{} 464 465 err = u2.Scan(s2) 466 require.Error(t, err) 467 } 468 469 func TestScanText(t *testing.T) { 470 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 471 b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 472 473 u1 := UUID{} 474 err := u1.Scan(b1) 475 require.NoError(t, err) 476 require.Equal(t, u, u1) 477 478 b2 := []byte("") 479 u2 := UUID{} 480 err = u2.Scan(b2) 481 require.Error(t, err) 482 } 483 484 func TestScanUnsupported(t *testing.T) { 485 u := UUID{} 486 487 err := u.Scan(true) 488 require.Error(t, err) 489 } 490 491 func TestScanNil(t *testing.T) { 492 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 493 494 err := u.Scan(nil) 495 require.NoError(t, err) 496 } 497 498 func TestBytes(t *testing.T) { 499 u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 500 501 bytes1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} 502 503 require.Equal(t, u.Bytes(), bytes1) 504 } 505 506 func TestString(t *testing.T) { 507 require.Equal(t, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", UUID_NAMESPACE_DNS.String()) 508 } 509 510 func TestEqual(t *testing.T) { 511 require.NotEqual(t, UUID_NAMESPACE_DNS, UUID_NAMESPACE_URL) 512 require.Equal(t, UUID_NAMESPACE_DNS, UUID_NAMESPACE_DNS) 513 } 514 515 func TestVersion(t *testing.T) { 516 u := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 517 require.Equal(t, UUID_V1, u.Version()) 518 } 519 520 func TestSetVersion(t *testing.T) { 521 u := UUID{} 522 u.SetVersion(4) 523 require.Equal(t, UUID_V4, u.Version()) 524 } 525 526 func TestVariant(t *testing.T) { 527 u1 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 528 require.Equal(t, UUID_VARIANT_NCS, u1.Variant()) 529 530 u2 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 531 require.Equal(t, UUID_VARIANT_RFC4122, u2.Variant()) 532 533 u3 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 534 require.Equal(t, UUID_VARIANT_MICROSOFT, u3.Variant()) 535 536 u4 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 537 require.Equal(t, UUID_VARIANT_FUTURE, u4.Variant()) 538 } 539 540 func TestSetVariant(t *testing.T) { 541 u := UUID{} 542 543 u.SetVariant(UUID_VARIANT_NCS) 544 require.Equal(t, UUID_VARIANT_NCS, u.Variant()) 545 546 u.SetVariant(UUID_VARIANT_RFC4122) 547 require.Equal(t, UUID_VARIANT_RFC4122, u.Variant()) 548 549 u.SetVariant(UUID_VARIANT_MICROSOFT) 550 require.Equal(t, UUID_VARIANT_MICROSOFT, u.Variant()) 551 552 u.SetVariant(UUID_VARIANT_FUTURE) 553 require.Equal(t, UUID_VARIANT_FUTURE, u.Variant()) 554 } 555 556 func TestMust(t *testing.T) { 557 require.Panics(t, func() { 558 UUID_OrPanic(func() (UUID, error) { 559 return _UUID_NULL, fmt.Errorf("uuid: expected error") 560 }()) 561 }) 562 }