email_cache_test.go 848 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build unit
  2. package repository
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestVerifyCodeKey(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. email string
  11. expected string
  12. }{
  13. {
  14. name: "normal_email",
  15. email: "user@example.com",
  16. expected: "verify_code:user@example.com",
  17. },
  18. {
  19. name: "empty_email",
  20. email: "",
  21. expected: "verify_code:",
  22. },
  23. {
  24. name: "email_with_plus",
  25. email: "user+tag@example.com",
  26. expected: "verify_code:user+tag@example.com",
  27. },
  28. {
  29. name: "email_with_special_chars",
  30. email: "user.name+tag@sub.domain.com",
  31. expected: "verify_code:user.name+tag@sub.domain.com",
  32. },
  33. }
  34. for _, tc := range tests {
  35. t.Run(tc.name, func(t *testing.T) {
  36. got := verifyCodeKey(tc.email)
  37. require.Equal(t, tc.expected, got)
  38. })
  39. }
  40. }