git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/ulid/ulid_test.go (about) 1 package ulid_test 2 3 import ( 4 "bytes" 5 "encoding/hex" 6 "fmt" 7 "testing" 8 "time" 9 10 "git.sr.ht/~pingoo/stdx/ulid" 11 ) 12 13 func TestNew(t *testing.T) { 14 for i := 0; i < 1000; i += 1 { 15 id := ulid.New() 16 time.Sleep(time.Millisecond) 17 fmt.Println(id.String(), "->", hex.EncodeToString(id[:])) 18 } 19 } 20 21 func TestParse(t *testing.T) { 22 for i := 0; i < 1000; i += 1 { 23 id := ulid.New() 24 parsed, err := ulid.Parse(id.String()) 25 if err != nil { 26 t.Errorf("parsing ulid: %s", err) 27 } 28 if !bytes.Equal(id[:], parsed[:]) { 29 t.Errorf("parsed (%s) != original ULID (%s)", parsed.String(), id.String()) 30 } 31 } 32 }