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.

63 lines
2.2 KiB

  1. /*
  2. * MinIO Object Storage (c) 2021 MinIO, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package cmd
  17. import (
  18. "testing"
  19. "github.com/minio/minio-go/v7/pkg/set"
  20. )
  21. func TestUpdateDomainIPs(t *testing.T) {
  22. tempGlobalMinioPort := globalMinioPort
  23. defer func() {
  24. globalMinioPort = tempGlobalMinioPort
  25. }()
  26. globalMinioPort = "9000"
  27. tempGlobalDomainIPs := globalDomainIPs
  28. defer func() {
  29. globalDomainIPs = tempGlobalDomainIPs
  30. }()
  31. ipv4TestCases := []struct {
  32. endPoints set.StringSet
  33. expectedResult set.StringSet
  34. }{
  35. {set.NewStringSet(), set.NewStringSet()},
  36. {set.CreateStringSet("localhost"), set.NewStringSet()},
  37. {set.CreateStringSet("localhost", "10.0.0.1"), set.CreateStringSet("10.0.0.1:9000")},
  38. {set.CreateStringSet("localhost:9001", "10.0.0.1"), set.CreateStringSet("10.0.0.1:9000")},
  39. {set.CreateStringSet("localhost", "10.0.0.1:9001"), set.CreateStringSet("10.0.0.1:9001")},
  40. {set.CreateStringSet("localhost:9000", "10.0.0.1:9001"), set.CreateStringSet("10.0.0.1:9001")},
  41. {set.CreateStringSet("10.0.0.1", "10.0.0.2"), set.CreateStringSet("10.0.0.1:9000", "10.0.0.2:9000")},
  42. {set.CreateStringSet("10.0.0.1:9001", "10.0.0.2"), set.CreateStringSet("10.0.0.1:9001", "10.0.0.2:9000")},
  43. {set.CreateStringSet("10.0.0.1", "10.0.0.2:9002"), set.CreateStringSet("10.0.0.1:9000", "10.0.0.2:9002")},
  44. {set.CreateStringSet("10.0.0.1:9001", "10.0.0.2:9002"), set.CreateStringSet("10.0.0.1:9001", "10.0.0.2:9002")},
  45. }
  46. for _, testCase := range ipv4TestCases {
  47. globalDomainIPs = nil
  48. updateDomainIPs(testCase.endPoints)
  49. if !testCase.expectedResult.Equals(globalDomainIPs) {
  50. t.Fatalf("error: expected = %s, got = %s", testCase.expectedResult, globalDomainIPs)
  51. }
  52. }
  53. }