redisclustermanager_test.go 946 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package redis
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestSplitClusterAddrs(t *testing.T) {
  7. testCases := []struct {
  8. name string
  9. input string
  10. expected []string
  11. }{
  12. {
  13. name: "empty input",
  14. input: "",
  15. expected: []string{""},
  16. },
  17. {
  18. name: "single address",
  19. input: "127.0.0.1:8000",
  20. expected: []string{"127.0.0.1:8000"},
  21. },
  22. {
  23. name: "multiple addresses with duplicates",
  24. input: "127.0.0.1:8000,127.0.0.1:8001, 127.0.0.1:8000",
  25. expected: []string{"127.0.0.1:8000", "127.0.0.1:8001"},
  26. },
  27. {
  28. name: "multiple addresses without duplicates",
  29. input: "127.0.0.1:8000, 127.0.0.1:8001, 127.0.0.1:8002",
  30. expected: []string{"127.0.0.1:8000", "127.0.0.1:8001", "127.0.0.1:8002"},
  31. },
  32. }
  33. for _, tc := range testCases {
  34. tc := tc
  35. t.Run(tc.name, func(t *testing.T) {
  36. assert.ElementsMatch(t, tc.expected, splitClusterAddrs(tc.input))
  37. })
  38. }
  39. }