stringutils_test.go 537 B

12345678910111213141516171819202122232425
  1. package stringutils
  2. import "testing"
  3. func TestRandomString(t *testing.T) {
  4. str := GenerateRandomString()
  5. if len(str) != 64 {
  6. t.Fatalf("Id returned is incorrect: %s", str)
  7. }
  8. }
  9. func TestRandomStringUniqueness(t *testing.T) {
  10. repeats := 25
  11. set := make(map[string]struct{}, repeats)
  12. for i := 0; i < repeats; i = i + 1 {
  13. str := GenerateRandomString()
  14. if len(str) != 64 {
  15. t.Fatalf("Id returned is incorrect: %s", str)
  16. }
  17. if _, ok := set[str]; ok {
  18. t.Fatalf("Random number is repeated")
  19. }
  20. set[str] = struct{}{}
  21. }
  22. }