| 1 | // Copyright (C) 2013-2018 by Maxim Bublis <[email protected]> |
| 2 | // |
| 3 | // Permission is hereby granted, free of charge, to any person obtaining |
| 4 | // a copy of this software and associated documentation files (the |
| 5 | // "Software"), to deal in the Software without restriction, including |
| 6 | // without limitation the rights to use, copy, modify, merge, publish, |
| 7 | // distribute, sublicense, and/or sell copies of the Software, and to |
| 8 | // permit persons to whom the Software is furnished to do so, subject to |
| 9 | // the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be |
| 12 | // included in all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | package uuidscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ |
| 23 | |
| 24 | import ( |
| 25 | "bytesscip-go gomod github.com/golang/go/src go1.25 bytes/" |
| 26 | "crypto/randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/" |
| 27 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/" |
| 28 | "errorsscip-go gomod github.com/golang/go/src go1.25 errors/" |
| 29 | "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/" |
| 30 | "netscip-go gomod github.com/golang/go/src go1.25 net/" |
| 31 | "stringsscip-go gomod github.com/golang/go/src go1.25 strings/" |
| 32 | "syncscip-go gomod github.com/golang/go/src go1.25 sync/" |
| 33 | "testingscip-go gomod github.com/golang/go/src go1.25 testing/" |
| 34 | "timescip-go gomod github.com/golang/go/src go1.25 time/" |
| 35 | ) |
| 36 | |
| 37 | func TestGeneratorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestGenerator().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 38 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV1", testNewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1().) |
| 39 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV3", testNewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3().) |
| 40 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV4", testNewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4().) |
| 41 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV5", testNewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5().) |
| 42 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV6", testNewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6().) |
| 43 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV7", testNewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV7().) |
| 44 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("NewV8", testNewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV8().) |
| 45 | } |
| 46 | |
| 47 | func testNewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 48 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", testNewV1Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1Basic().) |
| 49 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("BasicWithOptions", testNewV1BasicWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1BasicWithOptions().) |
| 50 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentAcrossCalls", testNewV1DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1DifferentAcrossCalls().) |
| 51 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("StaleEpoch", testNewV1StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1StaleEpoch().) |
| 52 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRand", testNewV1FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1FaultyRand().) |
| 53 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandWithOptions", testNewV1FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1FaultyRandWithOptions().) |
| 54 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("MissingNetwork", testNewV1MissingNetworkscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetwork().) |
| 55 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("MissingNetworkWithOptions", testNewV1MissingNetworkWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkWithOptions().) |
| 56 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("MissingNetworkFaultyRand", testNewV1MissingNetworkFaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkFaultyRand().) |
| 57 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("MissingNetworkFaultyRandWithOptions", testNewV1MissingNetworkFaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkFaultyRandWithOptions().) |
| 58 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("AtSpecificTime", testNewV1AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1AtTime().) |
| 59 | } |
| 60 | |
| 61 | func TestNewGenWithHWAFscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestNewGenWithHWAF().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 62 | addr := []byte{0, 1, 2, 3, 4, 42} |
| 63 | |
| 64 | fn := func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 65 | return addr, nil |
| 66 | } |
| 67 | |
| 68 | var g *Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen# |
| 69 | var err error |
| 70 | var uuid UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID# |
| 71 | |
| 72 | g = NewGenWithHWAFscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithHWAF().(fn) |
| 73 | |
| 74 | if g == nil { |
| 75 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("g is unexpectedly nil") |
| 76 | } |
| 77 | |
| 78 | uuid, err = g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 79 | if err != nil { |
| 80 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("g.NewV1() err = %v, want <nil>", err) |
| 81 | } |
| 82 | |
| 83 | node := uuid[10:] |
| 84 | |
| 85 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(addr, node) { |
| 86 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("node = %v, want %v", node, addr) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func testNewV1Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1Basic().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 91 | u, err := NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1().() |
| 92 | if err != nil { |
| 93 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 94 | } |
| 95 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V1.; got != want { |
| 96 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with version %d, want %d", got, want) |
| 97 | } |
| 98 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 99 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with variant %d, want %d", got, want) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func testNewV1BasicWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1BasicWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 104 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 105 | WithHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithHWAddrFunc().(nil), |
| 106 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(nil), |
| 107 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(nil), |
| 108 | ) |
| 109 | u, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 110 | if err != nil { |
| 111 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 112 | } |
| 113 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V1.; got != want { |
| 114 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with version %d, want %d", got, want) |
| 115 | } |
| 116 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 117 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with variant %d, want %d", got, want) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func testNewV1DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1DifferentAcrossCalls().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 122 | u1, err := NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1().() |
| 123 | if err != nil { |
| 124 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 125 | } |
| 126 | u2, err := NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1().() |
| 127 | if err != nil { |
| 128 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 129 | } |
| 130 | if u1 == u2 { |
| 131 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | func testNewV1StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1StaleEpoch().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 136 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 137 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 138 | return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(0, 0) |
| 139 | }, |
| 140 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 141 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Reader., |
| 142 | } |
| 143 | u1, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 144 | if err != nil { |
| 145 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 146 | } |
| 147 | u2, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 148 | if err != nil { |
| 149 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 150 | } |
| 151 | if u1 == u2 { |
| 152 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func testNewV1FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1FaultyRand().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 157 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 158 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 159 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 160 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 161 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 162 | }, |
| 163 | } |
| 164 | u, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 165 | if err == nil { |
| 166 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v, want error", u) |
| 167 | } |
| 168 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 169 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v on error, want Nil", u) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func testNewV1MissingNetworkscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetwork().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 174 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 175 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 176 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 177 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 178 | }, |
| 179 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Reader., |
| 180 | } |
| 181 | _, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 182 | if err != nil { |
| 183 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("did not handle missing network interfaces: %v", err) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | func testNewV1MissingNetworkWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 188 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 189 | WithHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithHWAddrFunc().(func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 190 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 191 | }), |
| 192 | ) |
| 193 | _, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 194 | if err != nil { |
| 195 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("did not handle missing network interfaces: %v", err) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | func testNewV1MissingNetworkFaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkFaultyRand().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 200 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 201 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 202 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 203 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 204 | }, |
| 205 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 206 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 1, |
| 207 | }, |
| 208 | } |
| 209 | u, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 210 | if err == nil { |
| 211 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("did not error on faulty reader and missing network, got %v", u) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | func testNewV1MissingNetworkFaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1MissingNetworkFaultyRandWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 216 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 217 | WithHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithHWAddrFunc().(func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 218 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 219 | }), |
| 220 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 221 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 1, |
| 222 | }), |
| 223 | ) |
| 224 | |
| 225 | u, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 226 | if err == nil { |
| 227 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("did not error on faulty reader and missing network, got %v", u) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func testNewV1AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1AtTime().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 232 | atTime := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2020, 1, 2, 3, 4, 5, 6, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.) |
| 233 | |
| 234 | u1, err := NewV1AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1AtTime().(atTime) |
| 235 | if err != nil { |
| 236 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 237 | } |
| 238 | |
| 239 | u2, err := NewV1AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1AtTime().(atTime) |
| 240 | if err != nil { |
| 241 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 242 | } |
| 243 | |
| 244 | // Even with the same timestamp, there is still a monotonically increasing portion, |
| 245 | // so they should not be 100% identical. Bytes 0-7 and 10-16 should be identical. |
| 246 | u1Bytes := u1.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().() |
| 247 | u2Bytes := u2.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().() |
| 248 | binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/bigEndian#PutUint16().(u1Bytes[8:], 0) |
| 249 | binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/bigEndian#PutUint16().(u2Bytes[8:], 0) |
| 250 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(u1Bytes, u2Bytes) { |
| 251 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated different UUIDs across calls with same timestamp: %v / %v", u1, u2) |
| 252 | } |
| 253 | |
| 254 | ts1, err := TimestampFromV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV1().(u1) |
| 255 | if err != nil { |
| 256 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 257 | } |
| 258 | time1, err := ts1.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 259 | if err != nil { |
| 260 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 261 | } |
| 262 | if time1.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 263 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 264 | } |
| 265 | ts2, err := TimestampFromV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV1().(u2) |
| 266 | if err != nil { |
| 267 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 268 | } |
| 269 | time2, err := ts2.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 270 | if err != nil { |
| 271 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 272 | } |
| 273 | if time2.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 274 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func testNewV1FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV1FaultyRandWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 279 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().(WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 280 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 281 | }), |
| 282 | ) |
| 283 | u, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().() |
| 284 | if err == nil { |
| 285 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("did not error on faulty reader and missing network, got %v", u) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | func testNewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 290 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", testNewV3Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3Basic().) |
| 291 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("EqualNames", testNewV3EqualNamesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3EqualNames().) |
| 292 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentNamespaces", testNewV3DifferentNamespacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3DifferentNamespaces().) |
| 293 | } |
| 294 | |
| 295 | func testNewV3Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3Basic().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 296 | ns := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 297 | name := "www.example.com" |
| 298 | u := NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(ns, name) |
| 299 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V3.; got != want { |
| 300 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV3(%v, %q): got version %d, want %d", ns, name, got, want) |
| 301 | } |
| 302 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 303 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV3(%v, %q): got variant %d, want %d", ns, name, got, want) |
| 304 | } |
| 305 | want := "5df41881-3aed-3515-88a7-2f4a814cf09e" |
| 306 | if got := u.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().(); got != want { |
| 307 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV3(%v, %q) = %q, want %q", ns, name, got, want) |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func testNewV3EqualNamesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3EqualNames().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 312 | ns := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 313 | name := "example.com" |
| 314 | u1 := NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(ns, name) |
| 315 | u2 := NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(ns, name) |
| 316 | if u1 != u2 { |
| 317 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV3(%v, %q) generated %v and %v across two calls", ns, name, u1, u2) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | func testNewV3DifferentNamespacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV3DifferentNamespaces().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 322 | name := "example.com" |
| 323 | ns1 := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 324 | ns2 := NamespaceURLscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceURL. |
| 325 | u1 := NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(ns1, name) |
| 326 | u2 := NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(ns2, name) |
| 327 | if u1 == u2 { |
| 328 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV3(%v, %q) == NewV3(%d, %q) (%v)", ns1, name, ns2, name, u1) |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | func testNewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 333 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", testNewV4Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4Basic().) |
| 334 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentAcrossCalls", testNewV4DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4DifferentAcrossCalls().) |
| 335 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRand", testNewV4FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4FaultyRand().) |
| 336 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandWithOptions", testNewV4FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4FaultyRandWithOptions().) |
| 337 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomRead", testNewV4ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4ShortRandomRead().) |
| 338 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomReadWithOptions", testNewV4ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4ShortRandomReadWithOptions().) |
| 339 | } |
| 340 | |
| 341 | func testNewV4Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4Basic().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 342 | u, err := NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV4().() |
| 343 | if err != nil { |
| 344 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 345 | } |
| 346 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V4.; got != want { |
| 347 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %d, want %d", got, want) |
| 348 | } |
| 349 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 350 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got variant %d, want %d", got, want) |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | func testNewV4DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4DifferentAcrossCalls().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 355 | u1, err := NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV4().() |
| 356 | if err != nil { |
| 357 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 358 | } |
| 359 | u2, err := NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV4().() |
| 360 | if err != nil { |
| 361 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 362 | } |
| 363 | if u1 == u2 { |
| 364 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | func testNewV4FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4FaultyRand().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 369 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 370 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 371 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 372 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 373 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 374 | }, |
| 375 | } |
| 376 | u, err := g.NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV4().() |
| 377 | if err == nil { |
| 378 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | func testNewV4FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4FaultyRandWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 383 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 384 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 385 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 386 | }), |
| 387 | ) |
| 388 | u, err := g.NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV4().() |
| 389 | if err == nil { |
| 390 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | func testNewV4ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4ShortRandomRead().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 395 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 396 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 397 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 398 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 399 | }, |
| 400 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{42}), |
| 401 | } |
| 402 | u, err := g.NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV4().() |
| 403 | if err == nil { |
| 404 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | func testNewV4ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV4ShortRandomReadWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 409 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 410 | WithHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithHWAddrFunc().(func() (netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#, error) { |
| 411 | return []byte{}, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("uuid: no hw address found") |
| 412 | }), |
| 413 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 414 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 415 | }), |
| 416 | ) |
| 417 | u, err := g.NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV4().() |
| 418 | if err == nil { |
| 419 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func testNewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 424 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", testNewV5Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5Basic().) |
| 425 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("EqualNames", testNewV5EqualNamesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5EqualNames().) |
| 426 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentNamespaces", testNewV5DifferentNamespacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5DifferentNamespaces().) |
| 427 | } |
| 428 | |
| 429 | func testNewV5Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5Basic().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 430 | ns := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 431 | name := "www.example.com" |
| 432 | u := NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(ns, name) |
| 433 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V5.; got != want { |
| 434 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV5(%v, %q): got version %d, want %d", ns, name, got, want) |
| 435 | } |
| 436 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 437 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV5(%v, %q): got variant %d, want %d", ns, name, got, want) |
| 438 | } |
| 439 | want := "2ed6657d-e927-568b-95e1-2665a8aea6a2" |
| 440 | if got := u.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().(); got != want { |
| 441 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV5(%v, %q) = %q, want %q", ns, name, got, want) |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | func testNewV5EqualNamesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5EqualNames().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 446 | ns := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 447 | name := "example.com" |
| 448 | u1 := NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(ns, name) |
| 449 | u2 := NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(ns, name) |
| 450 | if u1 != u2 { |
| 451 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV5(%v, %q) generated %v and %v across two calls", ns, name, u1, u2) |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | func testNewV5DifferentNamespacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV5DifferentNamespaces().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 456 | name := "example.com" |
| 457 | ns1 := NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS. |
| 458 | ns2 := NamespaceURLscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceURL. |
| 459 | u1 := NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(ns1, name) |
| 460 | u2 := NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(ns2, name) |
| 461 | if u1 == u2 { |
| 462 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("NewV5(%v, %q) == NewV5(%v, %q) (%v)", ns1, name, ns2, name, u1) |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | func testNewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 467 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", testNewV6Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6Basic().) |
| 468 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentAcrossCalls", testNewV6DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6DifferentAcrossCalls().) |
| 469 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("StaleEpoch", testNewV6StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6StaleEpoch().) |
| 470 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("StaleEpochWithOptions", testNewV6StaleEpochWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6StaleEpochWithOptions().) |
| 471 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRand", testNewV6FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6FaultyRand().) |
| 472 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandWithOptions", testNewV6FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6FaultyRandWithOptions().) |
| 473 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomRead", testNewV6ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6ShortRandomRead().) |
| 474 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomReadWithOptions", testNewV6ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6ShortRandomReadWithOptions().) |
| 475 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("KSortable", testNewV6KSortablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6KSortable().) |
| 476 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("AtSpecificTime", testNewV6AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6AtTime().) |
| 477 | } |
| 478 | |
| 479 | func testNewV6Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6Basic().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 480 | u, err := NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6().() |
| 481 | if err != nil { |
| 482 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 483 | } |
| 484 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V6.; got != want { |
| 485 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with version %d, want %d", got, want) |
| 486 | } |
| 487 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 488 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated UUID with variant %d, want %d", got, want) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | func testNewV6DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6DifferentAcrossCalls().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 493 | u1, err := NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6().() |
| 494 | if err != nil { |
| 495 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 496 | } |
| 497 | u2, err := NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6().() |
| 498 | if err != nil { |
| 499 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 500 | } |
| 501 | if u1 == u2 { |
| 502 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | func testNewV6StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6StaleEpoch().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 507 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 508 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 509 | return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(0, 0) |
| 510 | }, |
| 511 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 512 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Reader., |
| 513 | } |
| 514 | u1, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 515 | if err != nil { |
| 516 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 517 | } |
| 518 | u2, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 519 | if err != nil { |
| 520 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 521 | } |
| 522 | if u1 == u2 { |
| 523 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | func testNewV6StaleEpochWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6StaleEpochWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 528 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 529 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 530 | return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(0, 0) |
| 531 | }), |
| 532 | ) |
| 533 | u1, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 534 | if err != nil { |
| 535 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 536 | } |
| 537 | u2, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 538 | if err != nil { |
| 539 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 540 | } |
| 541 | if u1 == u2 { |
| 542 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | func testNewV6FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6FaultyRand().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 547 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("randomData", 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#) { |
| 548 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 549 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 550 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 551 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 552 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 553 | }, |
| 554 | } |
| 555 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 556 | if err == nil { |
| 557 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v, want error", u) |
| 558 | } |
| 559 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 560 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v on error, want Nil", u) |
| 561 | } |
| 562 | }) |
| 563 | |
| 564 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("clockSequence", 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#) { |
| 565 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 566 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 567 | hwAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#hwAddrFunc.: defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc()., |
| 568 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 569 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 1, // fail immediately |
| 570 | }, |
| 571 | } |
| 572 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 573 | if err == nil { |
| 574 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v, want error", u) |
| 575 | } |
| 576 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 577 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v on error, want Nil", u) |
| 578 | } |
| 579 | }) |
| 580 | } |
| 581 | |
| 582 | func testNewV6FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6FaultyRandWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 583 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("randomData", 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#) { |
| 584 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 585 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 586 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 587 | }), |
| 588 | ) |
| 589 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 590 | if err == nil { |
| 591 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v, want error", u) |
| 592 | } |
| 593 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 594 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v on error, want Nil", u) |
| 595 | } |
| 596 | }) |
| 597 | |
| 598 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("clockSequence", 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#) { |
| 599 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 600 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 601 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 1, // fail immediately |
| 602 | }), |
| 603 | ) |
| 604 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 605 | if err == nil { |
| 606 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v, want error", u) |
| 607 | } |
| 608 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 609 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got %v on error, want Nil", u) |
| 610 | } |
| 611 | }) |
| 612 | } |
| 613 | |
| 614 | func testNewV6ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6ShortRandomRead().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 615 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 616 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 617 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{42}), |
| 618 | } |
| 619 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 620 | if err == nil { |
| 621 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | func testNewV6ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6ShortRandomReadWithOptions().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 626 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 627 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{42})), |
| 628 | ) |
| 629 | u, err := g.NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV6().() |
| 630 | if err == nil { |
| 631 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | func testNewV6KSortablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6KSortable().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 636 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 10) |
| 637 | for i := range uuids { |
| 638 | u, err := NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6().() |
| 639 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV6()", "", err) |
| 640 | |
| 641 | uuids[i] = u |
| 642 | |
| 643 | timescip-go gomod github.com/golang/go/src go1.25 time/.Sleepscip-go gomod github.com/golang/go/src go1.25 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.25 time/.Microsecondscip-go gomod github.com/golang/go/src go1.25 time/Microsecond.) |
| 644 | } |
| 645 | |
| 646 | for i := 1; i < len(uuids); i++ { |
| 647 | p, n := uuids[i-1], uuids[i] |
| 648 | isLess := p.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() < n.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() |
| 649 | if !isLess { |
| 650 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("uuids[%d] (%s) not less than uuids[%d] (%s)", i-1, p, i, n) |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | func testNewV6AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV6AtTime().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 656 | atTime := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2020, 1, 2, 3, 4, 5, 6, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.) |
| 657 | |
| 658 | u1, err := NewV6AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6AtTime().(atTime) |
| 659 | if err != nil { |
| 660 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 661 | } |
| 662 | |
| 663 | u2, err := NewV6AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6AtTime().(atTime) |
| 664 | if err != nil { |
| 665 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 666 | } |
| 667 | |
| 668 | // Even with the same timestamp, there is still a random portion, |
| 669 | // so they should not be 100% identical. Bytes 0-8 are the timestamp so they should be identical. |
| 670 | u1Bytes := u1.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().()[:8] |
| 671 | u2Bytes := u2.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().()[:8] |
| 672 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(u1Bytes, u2Bytes) { |
| 673 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated different UUIDs across calls with same timestamp: %v / %v", u1, u2) |
| 674 | } |
| 675 | |
| 676 | ts1, err := TimestampFromV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV6().(u1) |
| 677 | if err != nil { |
| 678 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 679 | } |
| 680 | time1, err := ts1.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 681 | if err != nil { |
| 682 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 683 | } |
| 684 | if time1.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 685 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 686 | } |
| 687 | ts2, err := TimestampFromV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV6().(u2) |
| 688 | if err != nil { |
| 689 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 690 | } |
| 691 | time2, err := ts2.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 692 | if err != nil { |
| 693 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 694 | } |
| 695 | if time2.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 696 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | func testNewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV7().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 701 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", makeTestNewV7Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Basic().()) |
| 702 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("TestVector", makeTestNewV7TestVectorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7TestVector().()) |
| 703 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic10M", makeTestNewV7Basic10Mscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Basic10M().()) |
| 704 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("DifferentAcrossCalls", makeTestNewV7DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7DifferentAcrossCalls().()) |
| 705 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("StaleEpoch", makeTestNewV7StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7StaleEpoch().()) |
| 706 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("StaleEpochWithOptions", makeTestNewV7StaleEpochWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7StaleEpochWithOptions().()) |
| 707 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRand", makeTestNewV7FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRand().()) |
| 708 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandWithOptions", makeTestNewV7FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandWithOptions().()) |
| 709 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomRead", makeTestNewV7ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ShortRandomRead().()) |
| 710 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ShortRandomReadWithOptions", makeTestNewV7ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ShortRandomReadWithOptions().()) |
| 711 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("KSortable", makeTestNewV7KSortablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7KSortable().()) |
| 712 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("ClockSequence", makeTestNewV7ClockSequencescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ClockSequence().()) |
| 713 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("CounterRollover", makeTestNewV7CounterRolloverscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7CounterRollover().()) |
| 714 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Sequential1M", makeTestNewV7Sequential1Mscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Sequential1M().()) |
| 715 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("BorrowIsBounded", makeTestNewV7BorrowIsBoundedscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7BorrowIsBounded().()) |
| 716 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("CounterReseedsOnNewTick", makeTestNewV7CounterReseedsOnNewTickscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7CounterReseedsOnNewTick().()) |
| 717 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("MixedWithV1", makeTestNewV7MixedWithV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7MixedWithV1().()) |
| 718 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("BackwardsClock", makeTestNewV7BackwardsClockscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7BackwardsClock().()) |
| 719 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("AtTimeHistorical", makeTestNewV7AtTimeHistoricalscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTimeHistorical().()) |
| 720 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("AtTimeUnrepresentable", makeTestNewV7AtTimeUnrepresentablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTimeUnrepresentable().()) |
| 721 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Concurrent", makeTestNewV7Concurrentscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Concurrent().()) |
| 722 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandOnReseed", makeTestNewV7FaultyRandOnReseedscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandOnReseed().()) |
| 723 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("FaultyRandOnRollover", makeTestNewV7FaultyRandOnRolloverscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandOnRollover().()) |
| 724 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("AtSpecificTime", makeTestNewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTime().()) |
| 725 | } |
| 726 | |
| 727 | // v7Counter returns the 12 bits of rand_a that hold the monotonic counter. |
| 728 | func v7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7Counter().(u UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#) uint16 { |
| 729 | return binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/bigEndian#Uint16().(u[6:8]) & maxV7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/maxV7Counter. |
| 730 | } |
| 731 | |
| 732 | // assertV7Increasing fails on the first UUID that does not sort above its |
| 733 | // predecessor. A single generator should never produce one. |
| 734 | func assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#, uuids []UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#) { |
| 735 | t.Helperscip-go gomod github.com/golang/go/src go1.25 testing/common#Helper().() |
| 736 | |
| 737 | for i := 1; i < len(uuids); i++ { |
| 738 | p, n := uuids[i-1], uuids[i] |
| 739 | if p.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() >= n.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() { |
| 740 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("uuids[%d] (%s) not less than uuids[%d] (%s)", i-1, p, i, n) |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | func makeTestNewV7Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Basic().() 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#) { |
| 746 | return 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#) { |
| 747 | u, err := NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV7().() |
| 748 | if err != nil { |
| 749 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 750 | } |
| 751 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V7.; got != want { |
| 752 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %d, want %d", got, want) |
| 753 | } |
| 754 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 755 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got variant %d, want %d", got, want) |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // makeTestNewV7TestVector as defined in Draft04 |
| 761 | func makeTestNewV7TestVectorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7TestVector().() 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#) { |
| 762 | return 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#) { |
| 763 | pRand := make([]byte, 10) |
| 764 | // First 2 bytes will be read to seed the counter (11 bits are used; the top bit is cleared as a guard). |
| 765 | // The first 4 bits of u[6] will be overridden by the Version field. |
| 766 | binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/LittleEndian..PutUint16scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/littleEndian#PutUint16().(pRand[:2], uint16(0xCC3)) |
| 767 | // 8bytes will be read for rand_b. First 2 bits will be overridden by Variant |
| 768 | binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/LittleEndian..PutUint64scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/littleEndian#PutUint64().(pRand[2:], uint64(0x18C4DC0C0C07398F)) |
| 769 | |
| 770 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 771 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 772 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(1645557742000) |
| 773 | }, |
| 774 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().(pRand), |
| 775 | } |
| 776 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 777 | if err != nil { |
| 778 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 779 | } |
| 780 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V7.; got != want { |
| 781 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %d, want %d", got, want) |
| 782 | } |
| 783 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 784 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got variant %d, want %d", got, want) |
| 785 | } |
| 786 | if got, want := u.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().()[:15], "017f22e2-79b0-7"; got != want { |
| 787 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %q, want %q", got, want) |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | func makeTestNewV7Basic10Mscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Basic10M().() 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#) { |
| 793 | return 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#) { |
| 794 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 795 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 796 | } |
| 797 | |
| 798 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 799 | |
| 800 | for range 10_000_000 { |
| 801 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 802 | if err != nil { |
| 803 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 804 | } |
| 805 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V7.; got != want { |
| 806 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %d, want %d", got, want) |
| 807 | } |
| 808 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 809 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got variant %d, want %d", got, want) |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | func makeTestNewV7DifferentAcrossCallsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7DifferentAcrossCalls().() 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#) { |
| 816 | return 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#) { |
| 817 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 818 | |
| 819 | u1, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 820 | if err != nil { |
| 821 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 822 | } |
| 823 | u2, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 824 | if err != nil { |
| 825 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 826 | } |
| 827 | if u1 == u2 { |
| 828 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | func makeTestNewV7StaleEpochscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7StaleEpoch().() 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#) { |
| 834 | return 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#) { |
| 835 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 836 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 837 | return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(0, 0) |
| 838 | }, |
| 839 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Reader., |
| 840 | } |
| 841 | u1, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 842 | if err != nil { |
| 843 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 844 | } |
| 845 | u2, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 846 | if err != nil { |
| 847 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 848 | } |
| 849 | if u1 == u2 { |
| 850 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | func makeTestNewV7StaleEpochWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7StaleEpochWithOptions().() 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#) { |
| 856 | return 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#) { |
| 857 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 858 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 859 | return timescip-go gomod github.com/golang/go/src go1.25 time/.Unixscip-go gomod github.com/golang/go/src go1.25 time/Unix().(0, 0) |
| 860 | }), |
| 861 | ) |
| 862 | u1, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 863 | if err != nil { |
| 864 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 865 | } |
| 866 | u2, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 867 | if err != nil { |
| 868 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 869 | } |
| 870 | if u1 == u2 { |
| 871 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated identical UUIDs across calls: %v", u1) |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | func makeTestNewV7FaultyRandscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRand().() 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#) { |
| 877 | return 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#) { |
| 878 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 879 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 880 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 881 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, |
| 882 | }, |
| 883 | } |
| 884 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 885 | if err == nil { |
| 886 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error for clockSequence", u) |
| 887 | } |
| 888 | |
| 889 | g = &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 890 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 891 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: &faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 892 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 1, |
| 893 | }, |
| 894 | } |
| 895 | u, err = g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 896 | if err == nil { |
| 897 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error rand_b", u) |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | func makeTestNewV7FaultyRandWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandWithOptions().() 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#) { |
| 903 | return 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#) { |
| 904 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 905 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#{ |
| 906 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail.: 0, // fail immediately |
| 907 | }), |
| 908 | ) |
| 909 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 910 | if err == nil { |
| 911 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | func makeTestNewV7ShortRandomReadscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ShortRandomRead().() 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#) { |
| 917 | return 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#) { |
| 918 | g := &Genscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#{ |
| 919 | epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc.: timescip-go gomod github.com/golang/go/src go1.25 time/.Nowscip-go gomod github.com/golang/go/src go1.25 time/Now()., |
| 920 | randscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#rand.: bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{42}), |
| 921 | } |
| 922 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 923 | if err == nil { |
| 924 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | func makeTestNewV7ShortRandomReadWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ShortRandomReadWithOptions().() 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#) { |
| 930 | return 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#) { |
| 931 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 932 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().([]byte{42})), |
| 933 | ) |
| 934 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 935 | if err == nil { |
| 936 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error", u) |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | func makeTestNewV7KSortablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7KSortable().() 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#) { |
| 942 | return 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#) { |
| 943 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 10) |
| 944 | for i := range uuids { |
| 945 | u, err := NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV7().() |
| 946 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV7()", "", err) |
| 947 | |
| 948 | uuids[i] = u |
| 949 | timescip-go gomod github.com/golang/go/src go1.25 time/.Sleepscip-go gomod github.com/golang/go/src go1.25 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.25 time/.Millisecondscip-go gomod github.com/golang/go/src go1.25 time/Millisecond.) |
| 950 | } |
| 951 | |
| 952 | for i := 1; i < len(uuids); i++ { |
| 953 | p, n := uuids[i-1], uuids[i] |
| 954 | isLess := p.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() < n.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() |
| 955 | if !isLess { |
| 956 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("uuids[%d] (%s) not less than uuids[%d] (%s)", i-1, p, i, n) |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | func makeTestNewV7ClockSequencescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7ClockSequence().() 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#) { |
| 963 | return 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#) { |
| 964 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 965 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 966 | } |
| 967 | |
| 968 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 969 | //always return the same TS |
| 970 | g.epochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#epochFunc. = func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 971 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(1645557742000) |
| 972 | } |
| 973 | //by being KSortable with the same timestamp, it means the sequence is Not empty, and it is monotonic. |
| 974 | //The count is well past the 4096 values the 12 bit counter can hold, so a rollover has to be |
| 975 | //handled without breaking the ordering. |
| 976 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 5000) |
| 977 | for i := range uuids { |
| 978 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 979 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV7()", "", err) |
| 980 | uuids[i] = u |
| 981 | } |
| 982 | |
| 983 | assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t, uuids) |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // makeTestNewV7CounterRollover generates far more UUIDs within a single |
| 988 | // millisecond than the 12 bit counter can hold, which is where the counter used |
| 989 | // to wrap from 0xfff back to 0x000 and reorder UUIDs against their predecessor. |
| 990 | func makeTestNewV7CounterRolloverscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7CounterRollover().() 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#) { |
| 991 | return 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#) { |
| 992 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 993 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 994 | } |
| 995 | |
| 996 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().(WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 997 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(1645557742000) |
| 998 | })) |
| 999 | |
| 1000 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 50000) |
| 1001 | for i := range uuids { |
| 1002 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1003 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV7()", "", err) |
| 1004 | uuids[i] = u |
| 1005 | } |
| 1006 | |
| 1007 | assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t, uuids) |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | // makeTestNewV7Sequential1M is the ordering check at load, against the real |
| 1012 | // clock so that counter rollovers, the reseeding that follows them and the clock |
| 1013 | // advancing on its own all interleave. Sorting strictly above the previous UUID |
| 1014 | // also means differing from it, so this covers uniqueness across the run. UUIDs |
| 1015 | // are compared as they are generated rather than collected first, to keep the |
| 1016 | // count free to grow. |
| 1017 | func makeTestNewV7Sequential1Mscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Sequential1M().() 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#) { |
| 1018 | return 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#) { |
| 1019 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 1020 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 1021 | } |
| 1022 | |
| 1023 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 1024 | |
| 1025 | var prev string |
| 1026 | for i := range 1_000_000 { |
| 1027 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1028 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV7()", "", err) |
| 1029 | |
| 1030 | cur := u.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() |
| 1031 | if cur <= prev { |
| 1032 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("uuids[%d] (%s) not less than uuids[%d] (%s)", i-1, prev, i, cur) |
| 1033 | } |
| 1034 | prev = cur |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | // makeTestNewV7BorrowIsBounded checks the cost of the rollover handling: the |
| 1040 | // embedded timestamp runs ahead of the real one, but only by as many |
| 1041 | // milliseconds as there were counter rollovers. |
| 1042 | func makeTestNewV7BorrowIsBoundedscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7BorrowIsBounded().() 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#) { |
| 1043 | return 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#) { |
| 1044 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 1045 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 1046 | } |
| 1047 | |
| 1048 | const ( |
| 1049 | count = 50000 |
| 1050 | atMs = int64(1645557742000) |
| 1051 | usable = maxV7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/maxV7Counter. - v7CounterSeedMaskscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7CounterSeedMask. // increments guaranteed within a tick |
| 1052 | ) |
| 1053 | |
| 1054 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().(WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 1055 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(atMs) |
| 1056 | })) |
| 1057 | |
| 1058 | var last UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID# |
| 1059 | for range count { |
| 1060 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1061 | testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t, "NewV7()", "", err) |
| 1062 | last = u |
| 1063 | } |
| 1064 | |
| 1065 | ts, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(last) |
| 1066 | if err != nil { |
| 1067 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1068 | } |
| 1069 | got, err := ts.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1070 | if err != nil { |
| 1071 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1072 | } |
| 1073 | |
| 1074 | ahead := got.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/Time#UnixMilli().() - atMs |
| 1075 | if ahead < 0 { |
| 1076 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("timestamp went backwards by %dms", -ahead) |
| 1077 | } |
| 1078 | if want := int64(count/usable + 1); ahead > want { |
| 1079 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("timestamp ran %dms ahead of the clock, want at most %dms", ahead, want) |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | // makeTestNewV7CounterReseedsOnNewTick pins the random reader so the counter is |
| 1085 | // predictable, then checks that a new millisecond reseeds it from that reader |
| 1086 | // rather than continuing to climb, and that all 12 bits survive SetVersion. |
| 1087 | func makeTestNewV7CounterReseedsOnNewTickscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7CounterReseedsOnNewTick().() 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#) { |
| 1088 | return 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#) { |
| 1089 | // Two counter seeds, each followed by the 8 bytes read for rand_b. |
| 1090 | seeds := []uint16{0xabcd, 0x1234} |
| 1091 | buf := make([]byte, 0, 2*(2+8)) |
| 1092 | for _, seed := range seeds { |
| 1093 | buf = binaryscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/BigEndian..AppendUint16scip-go gomod github.com/golang/go/src go1.25 `encoding/binary`/bigEndian#AppendUint16().(buf, seed) |
| 1094 | buf = append(buf, make([]byte, 8)...) |
| 1095 | } |
| 1096 | |
| 1097 | ms := int64(1645557742000) |
| 1098 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 1099 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25 bytes/NewReader().(buf)), |
| 1100 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(ms) }), |
| 1101 | ) |
| 1102 | |
| 1103 | first, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1104 | if err != nil { |
| 1105 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1106 | } |
| 1107 | ms++ |
| 1108 | second, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1109 | if err != nil { |
| 1110 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1111 | } |
| 1112 | |
| 1113 | for i, u := range []UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#{first, second} { |
| 1114 | // The guard bit keeps the counter in the lower half of its range, |
| 1115 | // leaving room to increment within the tick. |
| 1116 | want := seeds[i] & v7CounterSeedMaskscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7CounterSeedMask. |
| 1117 | if got := v7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7Counter().(u); got != want { |
| 1118 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("uuid %d: got counter %#03x, want %#03x", i, got, want) |
| 1119 | } |
| 1120 | } |
| 1121 | if first.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() >= second.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() { |
| 1122 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("%v is not less than %v", first, second) |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | // makeTestNewV7MixedWithV1 guards against V7 sharing counter and timestamp state |
| 1128 | // with V1. V1 counts its epoch in 100 nanosecond intervals since 1582, which |
| 1129 | // dwarfs any millisecond value V7 compares against, and its clock sequence is 14 |
| 1130 | // bits wide rather than 12. The timestamp is pinned so that every UUID lands in |
| 1131 | // the same tick, leaving the counter as the only thing keeping them in order. |
| 1132 | func makeTestNewV7MixedWithV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7MixedWithV1().() 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#) { |
| 1133 | return 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#) { |
| 1134 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 1135 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 1136 | } |
| 1137 | |
| 1138 | const atMs = int64(1645557742000) |
| 1139 | |
| 1140 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().(WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 1141 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(atMs) |
| 1142 | })) |
| 1143 | |
| 1144 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 5000) |
| 1145 | for i := range uuids { |
| 1146 | if _, err := g.NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV1().(); err != nil { |
| 1147 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1148 | } |
| 1149 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1150 | if err != nil { |
| 1151 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1152 | } |
| 1153 | uuids[i] = u |
| 1154 | } |
| 1155 | |
| 1156 | assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t, uuids) |
| 1157 | |
| 1158 | // The V1 epoch must not have been mistaken for a millisecond count and |
| 1159 | // left in the V7 timestamp field. |
| 1160 | ts, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(uuids[0]) |
| 1161 | if err != nil { |
| 1162 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1163 | } |
| 1164 | got, err := ts.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1165 | if err != nil { |
| 1166 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1167 | } |
| 1168 | if got.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/Time#UnixMilli().() != atMs { |
| 1169 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("first UUID encodes %v (%dms), want the provided %dms", got.UTCscip-go gomod github.com/golang/go/src go1.25 time/Time#UTC().(), got.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/Time#UnixMilli().(), atMs) |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | // makeTestNewV7BackwardsClock checks that a clock correction cannot reorder |
| 1175 | // UUIDs, per the monotonic error checking guidance in RFC 9562 section 6.2. |
| 1176 | func makeTestNewV7BackwardsClockscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7BackwardsClock().() 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#) { |
| 1177 | return 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#) { |
| 1178 | ms := int64(1645557742000) |
| 1179 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().(WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { |
| 1180 | return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(ms) |
| 1181 | })) |
| 1182 | |
| 1183 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 0, 30) |
| 1184 | for _, step := range []int64{1, 1, -5000, 1, -1, 2} { |
| 1185 | for range 5 { |
| 1186 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1187 | if err != nil { |
| 1188 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1189 | } |
| 1190 | uuids = append(uuids, u) |
| 1191 | } |
| 1192 | ms += step |
| 1193 | } |
| 1194 | |
| 1195 | assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t, uuids) |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | // makeTestNewV7AtTimeHistorical checks that the protection against a backwards |
| 1200 | // clock does not leak into the explicit timestamp API: a caller asking for an |
| 1201 | // older timestamp gets that timestamp, and a batch at that timestamp stays |
| 1202 | // ordered. |
| 1203 | func makeTestNewV7AtTimeHistoricalscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTimeHistorical().() 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#) { |
| 1204 | return 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#) { |
| 1205 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 1206 | |
| 1207 | if _, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().(); err != nil { |
| 1208 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1209 | } |
| 1210 | |
| 1211 | atTime := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2020, 1, 2, 3, 4, 5, 0, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.) |
| 1212 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, 10) |
| 1213 | for i := range uuids { |
| 1214 | u, err := g.NewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7AtTime().(atTime) |
| 1215 | if err != nil { |
| 1216 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1217 | } |
| 1218 | uuids[i] = u |
| 1219 | } |
| 1220 | |
| 1221 | assertV7Increasingscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/assertV7Increasing().(t, uuids) |
| 1222 | |
| 1223 | for i, u := range uuids { |
| 1224 | ts, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(u) |
| 1225 | if err != nil { |
| 1226 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1227 | } |
| 1228 | got, err := ts.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1229 | if err != nil { |
| 1230 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1231 | } |
| 1232 | if !got.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 1233 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("uuids[%d] encodes %v, want the provided %v", i, got.UTCscip-go gomod github.com/golang/go/src go1.25 time/Time#UTC().(), atTime) |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | // makeTestNewV7AtTimeUnrepresentable covers times the 48-bit millisecond field |
| 1240 | // cannot hold, such as the zero time. They are pinned to the nearest end of the |
| 1241 | // range, and must not drag the generator along with them: without that, the |
| 1242 | // negative millisecond count of a zero time would read as a timestamp far in the |
| 1243 | // future and hold every later UUID there. |
| 1244 | func makeTestNewV7AtTimeUnrepresentablescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTimeUnrepresentable().() 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#) { |
| 1245 | return 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#) { |
| 1246 | for _, tt := range []struct { |
| 1247 | name string |
| 1248 | atTime timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# |
| 1249 | want int64 |
| 1250 | }{ |
| 1251 | {name: "ZeroTime", atTime: timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time#{}, want: 0}, |
| 1252 | {name: "BeforeUnixEpoch", atTime: timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(1969, 7, 20, 20, 17, 0, 0, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.), want: 0}, |
| 1253 | {name: "AfterTimestampRange", atTime: timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(20000, 1, 1, 0, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.), want: maxV7Timestampscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/maxV7Timestamp.}, |
| 1254 | } { |
| 1255 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().(tt.name, 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#) { |
| 1256 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 1257 | |
| 1258 | u, err := g.NewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7AtTime().(tt.atTime) |
| 1259 | if err != nil { |
| 1260 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1261 | } |
| 1262 | ts, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(u) |
| 1263 | if err != nil { |
| 1264 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1265 | } |
| 1266 | got, err := ts.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1267 | if err != nil { |
| 1268 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1269 | } |
| 1270 | if got.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/Time#UnixMilli().() != tt.want { |
| 1271 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("%v encodes %dms, want %dms", u, got.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/Time#UnixMilli().(), tt.want) |
| 1272 | } |
| 1273 | |
| 1274 | next, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1275 | if err != nil { |
| 1276 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1277 | } |
| 1278 | if u.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() >= next.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() { |
| 1279 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("%v is not less than %v", u, next) |
| 1280 | } |
| 1281 | |
| 1282 | if tt.want > 0 { |
| 1283 | // A timestamp ahead of the clock holds the generator there, |
| 1284 | // so there is nothing more to check. |
| 1285 | return |
| 1286 | } |
| 1287 | |
| 1288 | // A timestamp below the clock leaves the generator tracking it. |
| 1289 | ts, err = TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(next) |
| 1290 | if err != nil { |
| 1291 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1292 | } |
| 1293 | got, err = ts.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1294 | if err != nil { |
| 1295 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1296 | } |
| 1297 | if drift := timescip-go gomod github.com/golang/go/src go1.25 time/.Sincescip-go gomod github.com/golang/go/src go1.25 time/Since().(got); drift < 0 || drift > timescip-go gomod github.com/golang/go/src go1.25 time/.Minutescip-go gomod github.com/golang/go/src go1.25 time/Minute. { |
| 1298 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("%v is %v away from now", next, drift) |
| 1299 | } |
| 1300 | }) |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | // makeTestNewV7Concurrent checks that no two UUIDs from one generator share a |
| 1306 | // timestamp and counter, which is the pair the ordering guarantee rests on. |
| 1307 | func makeTestNewV7Concurrentscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7Concurrent().() 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#) { |
| 1308 | return 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#) { |
| 1309 | const ( |
| 1310 | goroutines = 8 |
| 1311 | perRoutine = 2000 |
| 1312 | ) |
| 1313 | |
| 1314 | g := NewGenscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGen().() |
| 1315 | |
| 1316 | var wg syncscip-go gomod github.com/golang/go/src go1.25 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25 sync/WaitGroup# |
| 1317 | results := make([][]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, goroutines) |
| 1318 | for i := range results { |
| 1319 | wg.Addscip-go gomod github.com/golang/go/src go1.25 sync/WaitGroup#Add().(1) |
| 1320 | go func(i int) { |
| 1321 | defer wg.Donescip-go gomod github.com/golang/go/src go1.25 sync/WaitGroup#Done().() |
| 1322 | |
| 1323 | uuids := make([]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, perRoutine) |
| 1324 | for j := range uuids { |
| 1325 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1326 | if err != nil { |
| 1327 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().(err) |
| 1328 | return |
| 1329 | } |
| 1330 | uuids[j] = u |
| 1331 | } |
| 1332 | results[i] = uuids |
| 1333 | }(i) |
| 1334 | } |
| 1335 | wg.Waitscip-go gomod github.com/golang/go/src go1.25 sync/WaitGroup#Wait().() |
| 1336 | |
| 1337 | if t.Failedscip-go gomod github.com/golang/go/src go1.25 testing/common#Failed().() { |
| 1338 | return |
| 1339 | } |
| 1340 | |
| 1341 | type sequence struct { |
| 1342 | ms uint64 |
| 1343 | counter uint16 |
| 1344 | } |
| 1345 | seen := make(map[sequence]UUIDscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#, goroutines*perRoutine) |
| 1346 | for _, uuids := range results { |
| 1347 | for _, u := range uuids { |
| 1348 | ts, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(u) |
| 1349 | if err != nil { |
| 1350 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1351 | } |
| 1352 | key := sequence{ms: uint64(ts), counter: v7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7Counter().(u)} |
| 1353 | if prev, ok := seen[key]; ok { |
| 1354 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("%v and %v share a timestamp and counter", prev, u) |
| 1355 | } |
| 1356 | seen[key] = u |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | // makeTestNewV7FaultyRandOnReseed fails the read that seeds the counter for a |
| 1363 | // new millisecond. |
| 1364 | func makeTestNewV7FaultyRandOnReseedscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandOnReseed().() 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#) { |
| 1365 | return 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#) { |
| 1366 | ms := int64(1645557742000) |
| 1367 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 1368 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&seedFailReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#{failOnscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#failOn.: 2}), |
| 1369 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(ms) }), |
| 1370 | ) |
| 1371 | |
| 1372 | if _, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().(); err != nil { |
| 1373 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1374 | } |
| 1375 | |
| 1376 | ms++ |
| 1377 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1378 | if err == nil { |
| 1379 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error for the counter reseed", u) |
| 1380 | } |
| 1381 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 1382 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v on error, want Nil", u) |
| 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | // makeTestNewV7FaultyRandOnRollover fails the read that reseeds the counter |
| 1388 | // after it is exhausted within a millisecond. Seeding the counter as high as the |
| 1389 | // guard bit allows also pins down the guaranteed headroom within a tick. |
| 1390 | func makeTestNewV7FaultyRandOnRolloverscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7FaultyRandOnRollover().() 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#) { |
| 1391 | return 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#) { |
| 1392 | if testingscip-go gomod github.com/golang/go/src go1.25 testing/.Shortscip-go gomod github.com/golang/go/src go1.25 testing/Short().() { |
| 1393 | t.Skipscip-go gomod github.com/golang/go/src go1.25 testing/common#Skip().("skipping test in short mode.") |
| 1394 | } |
| 1395 | |
| 1396 | g := NewGenWithOptionsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewGenWithOptions().( |
| 1397 | WithRandomReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithRandomReader().(&seedFailReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#{failOnscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#failOn.: 2}), |
| 1398 | WithEpochFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/WithEpochFunc().(func() timescip-go gomod github.com/golang/go/src go1.25 time/.Timescip-go gomod github.com/golang/go/src go1.25 time/Time# { return timescip-go gomod github.com/golang/go/src go1.25 time/.UnixMilliscip-go gomod github.com/golang/go/src go1.25 time/UnixMilli().(1645557742000) }), |
| 1399 | ) |
| 1400 | |
| 1401 | first, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1402 | if err != nil { |
| 1403 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1404 | } |
| 1405 | if got, want := v7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7Counter().(first), uint16(v7CounterSeedMaskscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7CounterSeedMask.); got != want { |
| 1406 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("got counter %#03x, want %#03x", got, want) |
| 1407 | } |
| 1408 | |
| 1409 | for i := range maxV7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/maxV7Counter. - v7CounterSeedMaskscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7CounterSeedMask. { |
| 1410 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1411 | if err != nil { |
| 1412 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("uuid %d: unexpected error: %v", i, err) |
| 1413 | } |
| 1414 | if got, want := v7Counterscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7Counter().(u), uint16(v7CounterSeedMaskscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/v7CounterSeedMask.+1+i); got != want { |
| 1415 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("uuid %d: got counter %#03x, want %#03x", i, got, want) |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | u, err := g.NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Gen#NewV7().() |
| 1420 | if err == nil { |
| 1421 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v, nil error for the counter rollover", u) |
| 1422 | } |
| 1423 | if u != Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 1424 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got %v on error, want Nil", u) |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | func makeTestNewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV7AtTime().() 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#) { |
| 1430 | return 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#) { |
| 1431 | atTime := timescip-go gomod github.com/golang/go/src go1.25 time/.Datescip-go gomod github.com/golang/go/src go1.25 time/Date().(2020, 1, 2, 3, 4, 5, 6, timescip-go gomod github.com/golang/go/src go1.25 time/.UTCscip-go gomod github.com/golang/go/src go1.25 time/UTC.) |
| 1432 | |
| 1433 | u1, err := NewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV7AtTime().(atTime) |
| 1434 | if err != nil { |
| 1435 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1436 | } |
| 1437 | |
| 1438 | u2, err := NewV7AtTimescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV7AtTime().(atTime) |
| 1439 | if err != nil { |
| 1440 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1441 | } |
| 1442 | |
| 1443 | // Bytes 0-5 hold the 48 bit timestamp, so they should be identical. The |
| 1444 | // remaining bytes carry the monotonic counter and the random portion, |
| 1445 | // which must differ so that the second UUID sorts above the first. |
| 1446 | u1Bytes := u1.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().()[:6] |
| 1447 | u2Bytes := u2.Bytesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Bytes().()[:6] |
| 1448 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(u1Bytes, u2Bytes) { |
| 1449 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("generated different UUIDs across calls with same timestamp: %v / %v", u1, u2) |
| 1450 | } |
| 1451 | if u1.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() >= u2.Stringscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#String().() { |
| 1452 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("%v is not less than %v", u1, u2) |
| 1453 | } |
| 1454 | |
| 1455 | ts1, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(u1) |
| 1456 | if err != nil { |
| 1457 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1458 | } |
| 1459 | time1, err := ts1.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1460 | if err != nil { |
| 1461 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1462 | } |
| 1463 | if time1.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 1464 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 1465 | } |
| 1466 | ts2, err := TimestampFromV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TimestampFromV7().(u2) |
| 1467 | if err != nil { |
| 1468 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1469 | } |
| 1470 | time2, err := ts2.Timescip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Timestamp#Time().() |
| 1471 | if err != nil { |
| 1472 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1473 | } |
| 1474 | if time2.Equalscip-go gomod github.com/golang/go/src go1.25 time/Time#Equal().(atTime) { |
| 1475 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("extracted time is incorrect: was %v, expected %v", time1, atTime) |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | func TestDefaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/TestDefaultHWAddrFunc().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 1481 | tests := []struct { |
| 1482 | n string |
| 1483 | fn 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) |
| 1484 | hw netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr# |
| 1485 | e string |
| 1486 | }{ |
| 1487 | { |
| 1488 | n: "Error", |
| 1489 | fn: 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) { |
| 1490 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Newscip-go gomod github.com/golang/go/src go1.25 errors/New().("controlled failure") |
| 1491 | }, |
| 1492 | e: "controlled failure", |
| 1493 | }, |
| 1494 | { |
| 1495 | n: "NoValidHWAddrReturned", |
| 1496 | fn: 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) { |
| 1497 | s := []netscip-go gomod github.com/golang/go/src go1.25 net/.Interfacescip-go gomod github.com/golang/go/src go1.25 net/Interface#{ |
| 1498 | { |
| 1499 | Indexscip-go gomod github.com/golang/go/src go1.25 net/Interface#Index.: 1, |
| 1500 | MTUscip-go gomod github.com/golang/go/src go1.25 net/Interface#MTU.: 1500, |
| 1501 | Namescip-go gomod github.com/golang/go/src go1.25 net/Interface#Name.: "test0", |
| 1502 | HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/Interface#HardwareAddr.: netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#{1, 2, 3, 4}, |
| 1503 | }, |
| 1504 | { |
| 1505 | Indexscip-go gomod github.com/golang/go/src go1.25 net/Interface#Index.: 2, |
| 1506 | MTUscip-go gomod github.com/golang/go/src go1.25 net/Interface#MTU.: 1500, |
| 1507 | Namescip-go gomod github.com/golang/go/src go1.25 net/Interface#Name.: "lo0", |
| 1508 | HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/Interface#HardwareAddr.: netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#{5, 6, 7, 8}, |
| 1509 | }, |
| 1510 | } |
| 1511 | |
| 1512 | return s, nil |
| 1513 | }, |
| 1514 | e: "uuid: no HW address found", |
| 1515 | }, |
| 1516 | { |
| 1517 | n: "ValidHWAddrReturned", |
| 1518 | fn: 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) { |
| 1519 | s := []netscip-go gomod github.com/golang/go/src go1.25 net/.Interfacescip-go gomod github.com/golang/go/src go1.25 net/Interface#{ |
| 1520 | { |
| 1521 | Indexscip-go gomod github.com/golang/go/src go1.25 net/Interface#Index.: 1, |
| 1522 | MTUscip-go gomod github.com/golang/go/src go1.25 net/Interface#MTU.: 1500, |
| 1523 | Namescip-go gomod github.com/golang/go/src go1.25 net/Interface#Name.: "test0", |
| 1524 | HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/Interface#HardwareAddr.: netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#{1, 2, 3, 4}, |
| 1525 | }, |
| 1526 | { |
| 1527 | Indexscip-go gomod github.com/golang/go/src go1.25 net/Interface#Index.: 2, |
| 1528 | MTUscip-go gomod github.com/golang/go/src go1.25 net/Interface#MTU.: 1500, |
| 1529 | Namescip-go gomod github.com/golang/go/src go1.25 net/Interface#Name.: "lo0", |
| 1530 | HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/Interface#HardwareAddr.: netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#{5, 6, 7, 8, 9, 0}, |
| 1531 | }, |
| 1532 | } |
| 1533 | |
| 1534 | return s, nil |
| 1535 | }, |
| 1536 | hw: netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr#{5, 6, 7, 8, 9, 0}, |
| 1537 | }, |
| 1538 | } |
| 1539 | |
| 1540 | for _, tt := range tests { |
| 1541 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().(tt.n, 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#) { |
| 1542 | // set the netInterfaces variable (function) for the test |
| 1543 | // and then set it back to default in the deferred function |
| 1544 | netInterfacesscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/netInterfaces. = tt.fn |
| 1545 | defer func() { |
| 1546 | 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(). |
| 1547 | }() |
| 1548 | |
| 1549 | var hw netscip-go gomod github.com/golang/go/src go1.25 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.25 net/HardwareAddr# |
| 1550 | var err error |
| 1551 | |
| 1552 | hw, err = defaultHWAddrFuncscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/defaultHWAddrFunc().() |
| 1553 | |
| 1554 | if len(tt.e) > 0 { |
| 1555 | if err == nil { |
| 1556 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("defaultHWAddrFunc() error = <nil>, should contain %q", tt.e) |
| 1557 | } |
| 1558 | |
| 1559 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(err.Error(), tt.e) { |
| 1560 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("defaultHWAddrFunc() error = %q, should contain %q", err.Error(), tt.e) |
| 1561 | } |
| 1562 | |
| 1563 | return |
| 1564 | } |
| 1565 | |
| 1566 | if err != nil && tt.e == "" { |
| 1567 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("defaultHWAddrFunc() error = %q, want <nil>", err.Error()) |
| 1568 | } |
| 1569 | |
| 1570 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(hw, tt.hw) { |
| 1571 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("hw = %#v, want %#v", hw, tt.hw) |
| 1572 | } |
| 1573 | }) |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | func BenchmarkGeneratorscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/BenchmarkGenerator().(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1578 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV1", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1579 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1580 | _, _ = NewV1scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV1().() |
| 1581 | } |
| 1582 | }) |
| 1583 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV3", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1584 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1585 | _ = NewV3scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV3().(NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS., "www.example.com") |
| 1586 | } |
| 1587 | }) |
| 1588 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV4", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1589 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1590 | _, _ = NewV4scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV4().() |
| 1591 | } |
| 1592 | }) |
| 1593 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV5", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1594 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1595 | _ = NewV5scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV5().(NamespaceDNSscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NamespaceDNS., "www.example.com") |
| 1596 | } |
| 1597 | }) |
| 1598 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV6", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1599 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1600 | _, _ = NewV6scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV6().() |
| 1601 | } |
| 1602 | }) |
| 1603 | b.Runscip-go gomod github.com/golang/go/src go1.25 testing/B#Run().("NewV7", func(b *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Bscip-go gomod github.com/golang/go/src go1.25 testing/B#) { |
| 1604 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25 testing/B#N.; i++ { |
| 1605 | _, _ = NewV7scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV7().() |
| 1606 | } |
| 1607 | }) |
| 1608 | } |
| 1609 | |
| 1610 | type faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader# struct { |
| 1611 | callsNumscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#callsNum. int |
| 1612 | readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail. int // Read call number to fail |
| 1613 | } |
| 1614 | |
| 1615 | func (r *faultyReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#) Readscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#Read().(dest []byte) (int, error) { |
| 1616 | r.callsNumscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#callsNum.++ |
| 1617 | if (r.callsNumscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#callsNum. - 1) == r.readToFailscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/faultyReader#readToFail. { |
| 1618 | return 0, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("io: reader is faulty") |
| 1619 | } |
| 1620 | return randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Read().(dest) |
| 1621 | } |
| 1622 | |
| 1623 | // seedFailReader fails a chosen V7 counter seed and serves every other seed as |
| 1624 | // 0xffff, which the guard bit trims to the highest value a seed can take. V7 |
| 1625 | // reads exactly two bytes for the counter seed and eight for rand_b, so the |
| 1626 | // length of the read identifies which is being served. |
| 1627 | type seedFailReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader# struct { |
| 1628 | seedsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#seeds. int |
| 1629 | failOnscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#failOn. int // seed number to fail, counting from one |
| 1630 | } |
| 1631 | |
| 1632 | func (r *seedFailReaderscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#) Readscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#Read().(dest []byte) (int, error) { |
| 1633 | if len(dest) != 2 { |
| 1634 | return randscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.25 `crypto/rand`/Read().(dest) |
| 1635 | } |
| 1636 | |
| 1637 | r.seedsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#seeds.++ |
| 1638 | if r.seedsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#seeds. == r.failOnscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/seedFailReader#failOn. { |
| 1639 | return 0, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("io: reader is faulty") |
| 1640 | } |
| 1641 | for i := range dest { |
| 1642 | dest[i] = 0xff |
| 1643 | } |
| 1644 | |
| 1645 | return len(dest), nil |
| 1646 | } |
| 1647 | |
| 1648 | // testErrCheck looks to see if errContains is a substring of err.Error(). If |
| 1649 | // not, this calls t.Fatal(). It also calls t.Fatal() if there was an error, but |
| 1650 | // errContains is empty. Returns true if you should continue running the test, |
| 1651 | // or false if you should stop the test. |
| 1652 | func testErrCheckscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testErrCheck().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#, name string, errContains string, err error) bool { |
| 1653 | t.Helperscip-go gomod github.com/golang/go/src go1.25 testing/common#Helper().() |
| 1654 | |
| 1655 | if len(errContains) > 0 { |
| 1656 | if err == nil { |
| 1657 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("%s error = <nil>, should contain %q", name, errContains) |
| 1658 | return false |
| 1659 | } |
| 1660 | |
| 1661 | if errStr := err.Error(); !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(errStr, errContains) { |
| 1662 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("%s error = %q, should contain %q", name, errStr, errContains) |
| 1663 | return false |
| 1664 | } |
| 1665 | |
| 1666 | return false |
| 1667 | } |
| 1668 | |
| 1669 | if err != nil && len(errContains) == 0 { |
| 1670 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatalf().("%s unexpected error: %v", name, err) |
| 1671 | return false |
| 1672 | } |
| 1673 | |
| 1674 | return true |
| 1675 | } |
| 1676 | |
| 1677 | func testNewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/testNewV8().(t *testingscip-go gomod github.com/golang/go/src go1.25 testing/.Tscip-go gomod github.com/golang/go/src go1.25 testing/T#) { |
| 1678 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("Basic", makeTestNewV8Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8Basic().()) |
| 1679 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("VersionAndVariant", makeTestNewV8VersionAndVariantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8VersionAndVariant().()) |
| 1680 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("CustomFields", makeTestNewV8CustomFieldsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8CustomFields().()) |
| 1681 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().("InvalidLength", makeTestNewV8InvalidLengthscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8InvalidLength().()) |
| 1682 | } |
| 1683 | |
| 1684 | func makeTestNewV8Basicscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8Basic().() 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#) { |
| 1685 | return 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#) { |
| 1686 | customA := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06} |
| 1687 | customB := []byte{0x07, 0x08} |
| 1688 | customC := []byte{0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10} |
| 1689 | |
| 1690 | u, err := NewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV8().(customA, customB, customC) |
| 1691 | if err != nil { |
| 1692 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1693 | } |
| 1694 | if u == Nilscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/Nil. { |
| 1695 | t.Errorscip-go gomod github.com/golang/go/src go1.25 testing/common#Error().("UUID is nil") |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | func makeTestNewV8VersionAndVariantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8VersionAndVariant().() 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#) { |
| 1701 | return 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#) { |
| 1702 | customA := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06} |
| 1703 | customB := []byte{0x07, 0x08} |
| 1704 | customC := []byte{0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10} |
| 1705 | |
| 1706 | u, err := NewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV8().(customA, customB, customC) |
| 1707 | if err != nil { |
| 1708 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1709 | } |
| 1710 | if got, want := u.Versionscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Version().(), V8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V8.; got != want { |
| 1711 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got version %d, want %d", got, want) |
| 1712 | } |
| 1713 | if got, want := u.Variantscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/UUID#Variant().(), VariantRFC9562scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/VariantRFC9562.; got != want { |
| 1714 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("got variant %d, want %d", got, want) |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | func makeTestNewV8CustomFieldsscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8CustomFields().() 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#) { |
| 1720 | return 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#) { |
| 1721 | // Test that custom data is correctly placed in the UUID |
| 1722 | // customA: 48 bits = 6 bytes -> u[0:6] |
| 1723 | // customB: 12 bits -> lower 12 bits of u[6:8] (high 4 bits are version) |
| 1724 | // customC: 62 bits -> lower 62 bits of u[8:16] (high 2 bits are variant) |
| 1725 | customA := []byte{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF} |
| 1726 | customB := []byte{0x01, 0x23} // 0x0123; only the lower 12 bits (0x123) are used |
| 1727 | customC := []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88} |
| 1728 | |
| 1729 | u, err := NewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV8().(customA, customB, customC) |
| 1730 | if err != nil { |
| 1731 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().(err) |
| 1732 | } |
| 1733 | |
| 1734 | // Check customA bytes |
| 1735 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(u[0:6], customA) { |
| 1736 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("customA mismatch: got %x, want %x", u[0:6], customA) |
| 1737 | } |
| 1738 | |
| 1739 | // Check version is set correctly (high nibble of byte 6) |
| 1740 | if u[6]>>4 != V8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V8. { |
| 1741 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("version bits incorrect: got %d, want %d", u[6]>>4, V8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/V8.) |
| 1742 | } |
| 1743 | |
| 1744 | // Check customB lower 12 bits (low nibble of u[6] and all of u[7]) |
| 1745 | bLow := (uint16(u[6]&0x0f) << 8) | uint16(u[7]) |
| 1746 | if bLow != 0x123 { |
| 1747 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("customB bits incorrect: got %x, want %x", bLow, 0x123) |
| 1748 | } |
| 1749 | |
| 1750 | // Check variant is set correctly (high 2 bits of byte 8) |
| 1751 | if (u[8] >> 6) != 0x02 { |
| 1752 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("variant bits incorrect: got %x, want %x", u[8]>>6, 0x02) |
| 1753 | } |
| 1754 | |
| 1755 | // Check customC lower 62 bits are preserved (excluding variant bits) |
| 1756 | wantC8 := (customC[0] & 0x3f) // variant overwrites top 2 bits |
| 1757 | // Actually the implementation masks u[8] before setting variant |
| 1758 | // So we expect the lower 6 bits of customC[0] to be in u[8], then variant added |
| 1759 | gotC8Lower := u[8] & 0x3f |
| 1760 | if gotC8Lower != wantC8 { |
| 1761 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("customC[0] lower bits incorrect: got %x, want %x", gotC8Lower, wantC8) |
| 1762 | } |
| 1763 | if !bytesscip-go gomod github.com/golang/go/src go1.25 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25 bytes/Equal().(u[9:16], customC[1:8]) { |
| 1764 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("customC[1:8] mismatch: got %x, want %x", u[9:16], customC[1:8]) |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | func makeTestNewV8InvalidLengthscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/makeTestNewV8InvalidLength().() 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#) { |
| 1770 | return 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#) { |
| 1771 | // Test that incorrect lengths return errors |
| 1772 | tests := []struct { |
| 1773 | name string |
| 1774 | customA []byte |
| 1775 | customB []byte |
| 1776 | customC []byte |
| 1777 | errMsg string |
| 1778 | }{ |
| 1779 | { |
| 1780 | name: "customA too short", |
| 1781 | customA: []byte{0x01, 0x02}, // 2 bytes instead of 6 |
| 1782 | customB: []byte{0x01, 0x23}, |
| 1783 | customC: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, |
| 1784 | errMsg: "customA must be exactly 6 bytes", |
| 1785 | }, |
| 1786 | { |
| 1787 | name: "customA too long", |
| 1788 | customA: []byte{0xFF, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, // 8 bytes |
| 1789 | customB: []byte{0x01, 0x23}, |
| 1790 | customC: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, |
| 1791 | errMsg: "customA must be exactly 6 bytes", |
| 1792 | }, |
| 1793 | { |
| 1794 | name: "customB too short", |
| 1795 | customA: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, |
| 1796 | customB: []byte{0x01}, // 1 byte instead of 2 |
| 1797 | customC: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, |
| 1798 | errMsg: "customB must be exactly 2 bytes", |
| 1799 | }, |
| 1800 | { |
| 1801 | name: "customB too long", |
| 1802 | customA: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, |
| 1803 | customB: []byte{0xFF, 0x01, 0x23}, // 3 bytes |
| 1804 | customC: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, |
| 1805 | errMsg: "customB must be exactly 2 bytes", |
| 1806 | }, |
| 1807 | { |
| 1808 | name: "customC too short", |
| 1809 | customA: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, |
| 1810 | customB: []byte{0x01, 0x23}, |
| 1811 | customC: []byte{0x01, 0x02}, // 2 bytes instead of 8 |
| 1812 | errMsg: "customC must be exactly 8 bytes", |
| 1813 | }, |
| 1814 | { |
| 1815 | name: "customC too long", |
| 1816 | customA: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, |
| 1817 | customB: []byte{0x01, 0x23}, |
| 1818 | customC: []byte{0xFF, 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, // 10 bytes |
| 1819 | errMsg: "customC must be exactly 8 bytes", |
| 1820 | }, |
| 1821 | { |
| 1822 | name: "all empty", |
| 1823 | customA: nil, |
| 1824 | customB: nil, |
| 1825 | customC: nil, |
| 1826 | errMsg: "customA must be exactly 6 bytes", |
| 1827 | }, |
| 1828 | } |
| 1829 | |
| 1830 | for _, tc := range tests { |
| 1831 | t.Runscip-go gomod github.com/golang/go/src go1.25 testing/T#Run().(tc.name, 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#) { |
| 1832 | _, err := NewV8scip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/NewV8().(tc.customA, tc.customB, tc.customC) |
| 1833 | if err == nil { |
| 1834 | t.Fatalscip-go gomod github.com/golang/go/src go1.25 testing/common#Fatal().("expected error, got nil") |
| 1835 | } |
| 1836 | if !errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Isscip-go gomod github.com/golang/go/src go1.25 errors/Is().(err, ErrV8FieldLengthscip-go gomod github.com/gofrs/uuid/v5 . `github.com/gofrs/uuid/v5`/ErrV8FieldLength.) { |
| 1837 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("expected ErrV8FieldLength, got %v", err) |
| 1838 | } |
| 1839 | if !stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Containsscip-go gomod github.com/golang/go/src go1.25 strings/Contains().(err.Error(), tc.errMsg) { |
| 1840 | t.Errorfscip-go gomod github.com/golang/go/src go1.25 testing/common#Errorf().("error message %q should contain %q", err.Error(), tc.errMsg) |
| 1841 | } |
| 1842 | }) |
| 1843 | } |
| 1844 | } |
| 1845 | } |