diff --git a/data/builder/dir_test.go b/data/builder/dir_test.go index 85eda58..a6ae711 100644 --- a/data/builder/dir_test.go +++ b/data/builder/dir_test.go @@ -4,13 +4,13 @@ import ( "bytes" "fmt" "io" + "math/rand/v2" "os" "path/filepath" "strconv" "testing" "github.com/ipfs/go-cid" - "github.com/ipfs/go-test/random" "github.com/ipfs/go-unixfsnode" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" @@ -19,6 +19,8 @@ import ( "github.com/stretchr/testify/require" ) +var chacha8Seed = [32]byte([]byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456")) + func mkEntries(cnt int, ls *ipld.LinkSystem) ([]dagpb.PBLink, error) { entries := make([]dagpb.PBLink, 0, cnt) for i := range cnt { @@ -41,10 +43,11 @@ func mkEntry(r io.Reader, name string, ls *ipld.LinkSystem) (dagpb.PBLink, error } func TestBuildUnixFSFileWrappedInDirectory_Reference(t *testing.T) { + rndSrc := rand.NewChaCha8(chacha8Seed) for _, tc := range referenceTestCases { t.Run(strconv.Itoa(tc.size), func(t *testing.T) { buf := make([]byte, tc.size) - random.NewSeededRand(0xdeadbeef).Read(buf) + rndSrc.Read(buf) r := bytes.NewReader(buf) ls := cidlink.DefaultLinkSystem() diff --git a/data/builder/file_test.go b/data/builder/file_test.go index cbd70b8..a5efd8b 100644 --- a/data/builder/file_test.go +++ b/data/builder/file_test.go @@ -3,11 +3,11 @@ package builder import ( "bytes" "context" + "math/rand/v2" "strconv" "testing" "github.com/ipfs/go-cid" - "github.com/ipfs/go-test/random" "github.com/ipfs/go-unixfsnode/file" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" @@ -24,33 +24,34 @@ var referenceTestCases = []struct { }{ { size: 1024, - bareExpected: cid.MustParse("bafkreigwqvgm5f6vgdv7wjkttdhgnkpbazhvuzvrqzaje4scb4moeinjum"), - wrappedExpected: cid.MustParse("bafybeib7rloaw4vl56brrnsetobsopu23e5ezoqxq4zorxxtljoeafcpca"), + bareExpected: cid.MustParse("bafkreifb7ur7vrppfjmfzdai64b7ps2kbknn3qm2h5rgekisk4p2invbma"), + wrappedExpected: cid.MustParse("bafybeid2kylejxunpqkja6n6mmkurkqresul35wyqebeemfzeqi3sdpuly"), }, { size: 10 * 1024, - bareExpected: cid.MustParse("bafkreihaxm6boumj2cwzbs3t3mnktfsgcf25ratcvtcf5kqnsymgk2gxqy"), - wrappedExpected: cid.MustParse("bafybeieogamws33kfbtpk5mdhoo2wkxwmd7dwnduyvo7wo65ll75d36xgi"), + bareExpected: cid.MustParse("bafkreib4e6kdlkbqflqxuajrc3gaojmg5h76z2uwcgylgk77rhdiymxprm"), + wrappedExpected: cid.MustParse("bafybeigcpq25l5lmit7yybb54k2m7azme32cux4ha42z2h6o7jhax2fpcm"), }, { size: 100 * 1024, - bareExpected: cid.MustParse("bafkreia7ockt35s5ki5qzrm37bp57woott6bju6gw64wl7rus7xwjcoemq"), - wrappedExpected: cid.MustParse("bafybeicywdnaqrwj3t7xltqgtaoi3ebk6fi2oyam6gsqle3bl4piucpzua"), + bareExpected: cid.MustParse("bafkreibf7lmsphxirotzojspxp2cg4swevwade3uctwakw5ite7cfjcu4i"), + wrappedExpected: cid.MustParse("bafybeig7pzfp2pamyj3umeusy5stwqulfsjucerrgwqgidur33dooomzze"), }, { size: 10 * 1024 * 1024, // https://github.com/ipfs/go-unixfs/blob/a7243ebfc36eaa89d79a39d3cef3fa1e60f7e49e/importer/importer_test.go#L49C1-L49C1 // QmZN1qquw84zhV4j6vT56tCcmFxaDaySL1ezTXFvMdNmrK, but with --cid-version=1 all the way through the DAG - bareExpected: cid.MustParse("bafybeibxlkafr6oqgflgjcjfbl5db6agozxdknpludvh7ym54oa5qoowbm"), - wrappedExpected: cid.MustParse("bafybeigqbp6jog6fvxbpq4opzcgn5rsp7xqrk7xa4zbgnqo6htjmolt3iy"), + bareExpected: cid.MustParse("bafybeihq2p6motnxdjdlhba7m6qt4xpor6n5rksasgfmfz4pq4jdh5p3e4"), + wrappedExpected: cid.MustParse("bafybeiehtvgdwqebeqzelc7adwhbcvfohyj6k5fxfwfqbncmf22mk2ezxm"), }, } func TestBuildUnixFSFile_Reference(t *testing.T) { + rndSrc := rand.NewChaCha8(chacha8Seed) for _, tc := range referenceTestCases { t.Run(strconv.Itoa(tc.size), func(t *testing.T) { buf := make([]byte, tc.size) - random.NewSeededRand(0xdeadbeef).Read(buf) + rndSrc.Read(buf) r := bytes.NewReader(buf) ls := cidlink.DefaultLinkSystem() @@ -74,7 +75,7 @@ func TestBuildUnixFSFile_Reference(t *testing.T) { func TestUnixFSFileRoundtrip(t *testing.T) { buf := make([]byte, 10*1024*1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8(chacha8Seed).Read(buf) r := bytes.NewReader(buf) ls := cidlink.DefaultLinkSystem() diff --git a/file/file_test.go b/file/file_test.go index 63faea3..09cfb57 100644 --- a/file/file_test.go +++ b/file/file_test.go @@ -5,9 +5,9 @@ import ( "context" "fmt" "io" + "math/rand/v2" "testing" - "github.com/ipfs/go-test/random" "github.com/ipfs/go-unixfsnode" "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipfs/go-unixfsnode/directory" @@ -19,6 +19,8 @@ import ( "github.com/ipld/go-ipld-prime/node/basicnode" ) +var chacha8Seed = [32]byte([]byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456")) + func TestRootV0File(t *testing.T) { baseFile := "./fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car" root, ls := open(baseFile, t) @@ -72,7 +74,7 @@ func TestFileSeeker(t *testing.T) { // Make random file with 1024 bytes. buf := make([]byte, 1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8(chacha8Seed).Read(buf) r := bytes.NewReader(buf) // Build UnixFS File as a single chunk diff --git a/file/large_file_test.go b/file/large_file_test.go index 1a0ea53..1b24857 100644 --- a/file/large_file_test.go +++ b/file/large_file_test.go @@ -7,12 +7,12 @@ import ( "context" "fmt" "io" + "math/rand/v2" "strconv" "sync" "testing" "github.com/ipfs/go-cid" - "github.com/ipfs/go-test/random" "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipfs/go-unixfsnode/file" dagpb "github.com/ipld/go-codec-dagpb" @@ -25,7 +25,7 @@ func TestLargeFileReader(t *testing.T) { t.Skip() } buf := make([]byte, 512*1024*1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8(chacha8Seed).Read(buf) r := bytes.NewReader(buf) ls := cidlink.DefaultLinkSystem() @@ -76,7 +76,7 @@ func TestLargeFileSeeker(t *testing.T) { // Make random file with 1024 bytes. buf := make([]byte, 1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8(chacha8Seed).Read(buf) r := bytes.NewReader(buf) // Build UnixFS File chunked in 256 byte parts. @@ -110,7 +110,7 @@ func TestLargeFileReaderReadsOnlyNecessaryBlocks(t *testing.T) { // Make random file with 1024 bytes. buf := make([]byte, 1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8(chacha8Seed).Read(buf) r := bytes.NewReader(buf) // Build UnixFS File chunked in 256 byte parts. diff --git a/go.mod b/go.mod index 377beb9..04ee73e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/ipfs/go-bitfield v1.1.0 github.com/ipfs/go-cid v0.6.2 github.com/ipfs/go-ipld-format v0.6.4 - github.com/ipfs/go-test v0.3.0 github.com/ipld/go-car/v2 v2.17.0 github.com/ipld/go-codec-dagpb v1.7.0 github.com/ipld/go-ipld-prime v0.24.0 @@ -22,7 +21,6 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect github.com/gammazero/chanqueue v1.1.2 // indirect github.com/gammazero/deque v1.2.1 // indirect github.com/go-logr/logr v1.4.3 // indirect @@ -40,13 +38,11 @@ require ( github.com/ipfs/go-metrics-interface v0.3.0 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-libp2p v0.48.0 // indirect github.com/mattn/go-isatty v0.0.22 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mr-tron/base58 v1.3.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr v0.16.1 // indirect github.com/multiformats/go-multibase v0.3.0 // indirect github.com/multiformats/go-varint v0.1.0 // indirect github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect diff --git a/go.sum b/go.sum index 6cf101a..91e9b80 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,6 @@ github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0= github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= -github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= github.com/filecoin-project/go-clock v0.1.0 h1:SFbYIM75M8NnFm1yMHhN9Ahy3W5bEZV9gd6MPfXbKVU= diff --git a/test/partial_file_access_test.go b/test/partial_file_access_test.go index 7549c8b..9f5d58a 100644 --- a/test/partial_file_access_test.go +++ b/test/partial_file_access_test.go @@ -4,9 +4,9 @@ import ( "bytes" "context" "io" + "math/rand/v2" "testing" - "github.com/ipfs/go-test/random" "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipfs/go-unixfsnode/file" dagpb "github.com/ipld/go-codec-dagpb" @@ -21,7 +21,7 @@ import ( func TestPartialFileAccess(t *testing.T) { buf := make([]byte, 10*1024*1024) - random.NewSeededRand(0xdeadbeef).Read(buf) + rand.NewChaCha8([32]byte([]byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"))).Read(buf) r := bytes.NewReader(buf) ls := cidlink.DefaultLinkSystem() diff --git a/testutil/namegen/namegen.go b/testutil/namegen/namegen.go index 376f0e0..7886b7e 100644 --- a/testutil/namegen/namegen.go +++ b/testutil/namegen/namegen.go @@ -6,30 +6,44 @@ import ( "strings" ) -var words = strings.Fields(wordData) -var extensions = []string{"", ".txt", ".pdf", ".docx", ".png", ".jpg", ".csv", ".json", ".xml"} +var Alphabet = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzáäåèêëíîïøúýþāăąċčďđĕęěğħķĺłňōŕřŝşšţťŧŭŵžƒƿǩνοςυвгкмпъяѐѓљғԁḽḿṕẓẽịỏụỳ") +var extensions = []string{"", ".bz2", ".car", ".csv", ".docx", ".jpg", ".json", ".md", ".mp4", ".pdf", ".png", ".tar", ".txt", ".txt.gz", ".xml", ".xz"} -func getRandomIndex(r io.Reader, max int) (int, error) { - var n uint32 - err := binary.Read(r, binary.BigEndian, &n) - if err != nil { - return 0, err +func RandomName(r io.Reader, minSize, maxSize int) (string, error) { + if minSize > maxSize { + minSize, maxSize = maxSize, minSize } - return int(n % uint32(max)), nil + sizeDiff := maxSize - minSize + size := minSize + if sizeDiff != 0 { + rn, err := randIntn(r, sizeDiff+1) + if err != nil { + return "", err + } + size += rn + } + + if size <= 0 { + return "", nil + } + src := make([]byte, size) + r.Read(src) + var b strings.Builder + for i := range src { + ch := Alphabet[int(src[i])%len(Alphabet)] + b.WriteRune(ch) + } + return b.String(), nil } // RandomDirectoryName returns a random directory name from the provided word list. func RandomDirectoryName(r io.Reader) (string, error) { - index, err := getRandomIndex(r, len(words)) - if err != nil { - return "", err - } - return words[index], nil + return RandomName(r, 5, 20) } // RandomFileName returns a random file name with an extension from the provided word list and common extensions. func RandomFileName(r io.Reader) (string, error) { - wordIndex, err := getRandomIndex(r, len(words)) + name, err := RandomName(r, 5, 20) if err != nil { return "", err } @@ -37,80 +51,25 @@ func RandomFileName(r io.Reader) (string, error) { if err != nil { return "", err } - return words[wordIndex] + ext, nil + return name + ext, nil } // RandomFileExtension returns a random file extension, including '.'. This may // also return an empty string. func RandomFileExtension(r io.Reader) (string, error) { - index, err := getRandomIndex(r, len(extensions)) + index, err := randIntn(r, len(extensions)) if err != nil { return "", err } return extensions[index], nil } -const wordData = `jabberwocky Snark whiffling borogoves mome raths brillig slithy toves outgrabe -Tumtum Frabjous Bandersnatch Jubjub Callay slumgullion snicker-snack brobdingnagian Jabberwock -tree Poglorian Binkleborf Wockbristle Zizzotether dinglewock Flumgurgle Glimperwick RazzleDazzle8 -gyre tortlewhack whispyfangle Crumplehorn Higgledy7 Piggledy3 flibberwocky Zamborot Flizzleflink -gimble Shakespearean Macbeth Othello Hamlet soliloquy iambic pentameter Benvolio Capulet Montague -Puck Malvolio Beatrice Prospero Iago Falstaff Rosencrantz Guildenstern Cordelia Polonius -Titania Oberon Tybalt Caliban Mercutio Portia Brabantio 4Lear Desdemona Lysander -YossarianScar Jujimufu9 Gorgulon Oozyboozle Razzmatazz8 BlinkenWoggle Flibbertigibbet Quixotic2 -Galumphing Widdershins Pecksniffian Bandicoot11 Flapdoodle Fandango Whippersnapper Grandiloquent -Lollygag Persnickety Gibberish Codswallop Rigmarole Nincompoop Flummox Snollygoster Poppycock -Kerfuffle Balderdash Gobbledygook Fiddle-faddle Antidisestablishmentarianism -Supercalifragilisticexpialidocious Rambunctious9 Lickety-split Hullabaloo Skullduggery Ballyhoo -Flabbergasted Discombobulate Pernicious Bumfuzzle Bamboozle Pandemonium Tomfoolery Hobbledehoy7 -Claptrap Cockamamie Hocus-pocus8 Higgledy-piggledy Dodecahedron Nonsensical Contraption Quizzical -Snuffleupagus Ostentatious Serendipity Ephemeral Melancholy Sonorous Plethora Brouhaha Absquatulate -Gobbledygook3 Lilliputian Chortle Euphonious Mellifluous Obfuscate Perspicacious Prevaricate -Sesquipedalian Tintinnabulation Quibble9 Umbrageous Quotidian Flapdoodle5 NoodleDoodle -Zigzagumptious Throttlebottom WuzzleWump Canoodle Hodgepodge Blatherskite7 Hornswoggle -BibbidiBobbidiBoo Prestidigitation Confabulate Abscond8 Lickspittle Ragamuffin Taradiddle -Widdershins4 Boondoggle Snuffleupagus9 Gallivant Folderol Malarkey Skedaddle Hobgoblin -BlubberCrumble ZibberZap Snickerdoodle Mooncalf LicketySplit8 Whatchamacallit Thingamajig -Thingamabob GibbleGabble FuddleDuddle LoopyLoo Splendiferous Bumbershoot Catawampus Flibbertigibbet5 -Gobbledygook7 Whippersnapper9 Ragamuffin8 Splendiferous -ætheling witan ealdorman leofwyrd swain bēorhall beorn mēarh scōp cyning hēahgerefa -sceadugenga wilweorc hildoræswa þegn ælfscyne wyrmslaga wælwulf fyrd hrēowmōd dēor -ealdorleornung scyldwiga þēodcwealm hāligbōc gūþweard wealdend gāstcynn wīfmann -wīsestōw þrēatung rīcere scealc eorþwerod bealucræft cynerīce sceorp ættwer -gāsthof ealdrīce wæpnedmann wæterfōr landgemære gafolgelda wīcstede mægenþrymm -æscwiga læcedōm wīdferhþ eorlgestrēon brimrād wæterstede hūslēoþ searocraeft -þegnunga wælscenc þrīstguma fyrdrinc wundorcræft cræftleornung eorþbūend -sǣlācend þunorrad wætergifu wæterscipe wæterþenung eorþtilþ eorþgebyrde -eorþhæbbend eorþgræf eorþbærn eorþhūs eorþscearu eorþsweg eorþtæfl eorþweorc -eorþweall eorþwaru eorþwela eorþwīs eorþworn eorþyþ eorþweg eorþwīse eorþwyrhta -eorþwīn eorþsceaða eorþsweart eorþscræf eorþscrūd eorþswyft eorþscīr eorþscūa -eorþsēoc eorþsele eorþhūsl eorþsted eorþswyn eorþsittend eorþsniþ eorþscearp -eorþscyld eorþsceaft eorþstapol eorþstede eorþsmitta eorþscēawere -velociraptorious chimeraesque bellerophontic serendipitastic transmogrification ultracrepidarian -prestidigitationary supraluminescence hemidemisemiquaver unquestionability intercontinentalism -antediluvianistic disproportionately absquatulationism automagicalization -floccinaucinihilipilification quintessentiality incomprehensibility juxtapositionally -perpendicularitude transubstantiation synchronicityverse astronomicalunit thermodynamicness -electromagnetismal procrastinatorily disenfranchisement neutrinooscillation hyperventilatingly -pneumonoultramicroscopicsilicovolcanoconiosis supercalifragilisticexpialidocious thaumaturgeonomics -idiosyncratically unencumberedness phantasmagoricity extraterrestrialism philanthropistastic -xenotransplantation incontrovertibility spontaneityvolution teleportationally labyrinthinean -megalomaniaction cryptozoologician ineffablemystique multiplicativity sisypheanquandary -overenthusiastically irrefutablenotion exceptionalitysphere -blibby ploof twindle zibbet jinty wiblo glimsy snaft trindle quopp vistly chark plizet snibber frint -trazzle buvvy skipple flizz dworp grindle yipple zarfle clippet swazz mibber brackle tindle grozz -vindle plazz freggle twazz snuzzle gwippet whindle juzzle krazz yazzle flippet skindle zapple prazz -buzzle chazz gripple snozzle trizz wazzle blikket zib glup snof yipr tazz vlim frub dwex klop -aa ab ad ae ag ah ai al am an as at aw ax ay ba be bi bo by de do ed ef eh el em en er es et ex fa -fe go ha he hi hm ho id if in is it jo ka ki la li lo ma me mi mm mo mu my na ne no nu od oe of oh -oi om on op or os ow ox oy pa pe pi qi re sh si so ta ti to uh um un up us ut we wo xi xu ya ye yo -za zo -hĕlłø cąfѐ ŝmîłe þřęê ċỏẽxist ǩāŕáōķê ŧrävèl кυгiοsity ŭпịςørn мëĺōđỳ ğħōšţ ŵăνę ẓẽṕhýr ғụzzlę -пåŕŧy 僃êct ԁяêåм љúвïĺëë ѓåḿъḽë ţęmƿęşţ říše čajovna želva štěstí ýpsilon ďábel ňadraží ťava -h3ll0 w0rld c0d1ng 3x3mpl3 pr0gr4mm1ng d3v3l0p3r 5cr4bbl3 3l3ph4nt 4pp 5y5t3m 1nput 0utput 3rr0r -5t4ck0v3rfl0w 5tr1ng 5l1c3 5h4k35p34r3 5t4nd4rd 3ncrypt10n 5h3ll 5cr1pt 5t4ck 5qu4r3 r3ct4ngl3 -tr14ngl3 c1rc13 5ph3r3 5qu4r3r00t 3xpr35510n 5t4t15t1c5 5t4t3m3nt 5ynt4x 5ugg35t10n 5y5t3m4t1c -5h0rtcut 5h4d0w 5h4r3d -1 2 3 4 5 6 7 8 9 0 -a b c d e f g h i j k l m n o p q r s t u v w x y z -A B C D E F G H I J K L M N O P Q R S T U V W X Y Z` +func randIntn(r io.Reader, max int) (int, error) { + var buf32 [4]byte + _, err := io.ReadFull(r, buf32[:]) + if err != nil { + return 0, err + } + n := binary.BigEndian.Uint32(buf32[:]) + return int(n % uint32(max)), nil +} diff --git a/testutil/namegen/namegen_test.go b/testutil/namegen/namegen_test.go new file mode 100644 index 0000000..c9bb075 --- /dev/null +++ b/testutil/namegen/namegen_test.go @@ -0,0 +1,63 @@ +package namegen_test + +import ( + crand "crypto/rand" + "math/rand/v2" + "strings" + "testing" + "unicode/utf8" + + "github.com/ipfs/go-unixfsnode/testutil/namegen" + "github.com/stretchr/testify/require" +) + +func TestRandomName(t *testing.T) { + var seed [32]byte + _, _ = crand.Read(seed[:]) + rndSrc := rand.NewChaCha8(seed) + + name, err := namegen.RandomName(rndSrc, 256, 256) + require.NoError(t, err) + require.Equal(t, 256, utf8.RuneCountInString(name)) + + // Check that each character in name is from the namegen.Alphabet. + for _, ch := range name { + require.Containsf(t, namegen.Alphabet, ch, "namegen.Alphabet does not contain %q", string(ch)) + } + + // Check that all possible characters are generated. + wantChars := make(map[rune]struct{}, len(namegen.Alphabet)) + for _, ch := range namegen.Alphabet { + wantChars[ch] = struct{}{} + } + const maxTries = 10000 + var tries int + for len(wantChars) != 0 { + if tries == maxTries { + var b strings.Builder + for ch := range wantChars { + b.WriteRune(ch) + } + t.Fatal("did not generate all posible characters, missing", b.String()) + } + name, err = namegen.RandomName(rndSrc, 256, 256) + require.NoError(t, err) + for _, ch := range name { + delete(wantChars, ch) + } + tries++ + + } +} + +func TestRandomFileName(t *testing.T) { + var seed [32]byte + _, _ = crand.Read(seed[:]) + rndSrc := rand.NewChaCha8(seed) + + for range 5 { + name, err := namegen.RandomFileName(rndSrc) + require.NoError(t, err) + t.Log(name) + } +}