You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client_test.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2019 Shivaram Lingamneni
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "testing"
  6. )
  7. func TestGenerateBatchID(t *testing.T) {
  8. var session Session
  9. s := make(StringSet)
  10. count := 100000
  11. for i := 0; i < count; i++ {
  12. s.Add(session.generateBatchID())
  13. }
  14. if len(s) != count {
  15. t.Error("duplicate batch ID detected")
  16. }
  17. }
  18. func BenchmarkGenerateBatchID(b *testing.B) {
  19. var session Session
  20. for i := 0; i < b.N; i++ {
  21. session.generateBatchID()
  22. }
  23. }
  24. func TestUserMasks(t *testing.T) {
  25. var um UserMaskSet
  26. if um.Match("horse_!user@tor-network.onion") {
  27. t.Error("bad match")
  28. }
  29. um.Add("_!*@*", "x", "x")
  30. if !um.Match("_!user@tor-network.onion") {
  31. t.Error("failure to match")
  32. }
  33. if um.Match("horse_!user@tor-network.onion") {
  34. t.Error("bad match")
  35. }
  36. um.Add("beer*!*@*", "x", "x")
  37. if !um.Match("beergarden!user@tor-network.onion") {
  38. t.Error("failure to match")
  39. }
  40. if um.Match("horse_!user@tor-network.onion") {
  41. t.Error("bad match")
  42. }
  43. um.Add("horse*!user@*", "x", "x")
  44. if !um.Match("horse_!user@tor-network.onion") {
  45. t.Error("failure to match")
  46. }
  47. }