redisclustermanager_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package redis
  2. import (
  3. "testing"
  4. "github.com/alicebob/miniredis/v2"
  5. red "github.com/go-redis/redis/v8"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestSplitClusterAddrs(t *testing.T) {
  9. testCases := []struct {
  10. name string
  11. input string
  12. expected []string
  13. }{
  14. {
  15. name: "empty input",
  16. input: "",
  17. expected: []string{""},
  18. },
  19. {
  20. name: "single address",
  21. input: "127.0.0.1:8000",
  22. expected: []string{"127.0.0.1:8000"},
  23. },
  24. {
  25. name: "multiple addresses with duplicates",
  26. input: "127.0.0.1:8000,127.0.0.1:8001, 127.0.0.1:8000",
  27. expected: []string{"127.0.0.1:8000", "127.0.0.1:8001"},
  28. },
  29. {
  30. name: "multiple addresses without duplicates",
  31. input: "127.0.0.1:8000, 127.0.0.1:8001, 127.0.0.1:8002",
  32. expected: []string{"127.0.0.1:8000", "127.0.0.1:8001", "127.0.0.1:8002"},
  33. },
  34. }
  35. for _, tc := range testCases {
  36. tc := tc
  37. t.Run(tc.name, func(t *testing.T) {
  38. assert.ElementsMatch(t, tc.expected, splitClusterAddrs(tc.input))
  39. })
  40. }
  41. }
  42. func TestGetCluster(t *testing.T) {
  43. r := miniredis.RunT(t)
  44. defer r.Close()
  45. c, err := getCluster(&Redis{
  46. Addr: r.Addr(),
  47. Type: ClusterType,
  48. tls: true,
  49. hooks: []red.Hook{durationHook},
  50. })
  51. if assert.NoError(t, err) {
  52. assert.NotNil(t, c)
  53. }
  54. }