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
1.7 KiB

  1. /*
  2. * Minio Cloud Storage, (C) 2016 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. "net/url"
  19. "reflect"
  20. "testing"
  21. )
  22. // Validates makeS3Peers, fetches all peers based on list of storage
  23. // endpoints.
  24. func TestMakeS3Peers(t *testing.T) {
  25. // Initialize configuration
  26. root, err := newTestConfig("us-east-1")
  27. if err != nil {
  28. t.Fatalf("%s", err)
  29. }
  30. defer removeAll(root)
  31. // test cases
  32. testCases := []struct {
  33. gMinioAddr string
  34. eps []*url.URL
  35. peers []string
  36. }{
  37. {":9000", []*url.URL{{Path: "/mnt/disk1"}}, []string{":9000"}},
  38. {":9000", []*url.URL{{Host: "localhost:9001"}}, []string{":9000", "localhost:9001"}},
  39. {"m1:9000", []*url.URL{{Host: "m1:9000"}, {Host: "m2:9000"}, {Host: "m3:9000"}}, []string{"m1:9000", "m2:9000", "m3:9000"}},
  40. }
  41. getPeersHelper := func(s3p s3Peers) []string {
  42. r := []string{}
  43. for _, p := range s3p {
  44. r = append(r, p.addr)
  45. }
  46. return r
  47. }
  48. // execute tests
  49. for i, testCase := range testCases {
  50. globalMinioAddr = testCase.gMinioAddr
  51. s3peers := makeS3Peers(testCase.eps)
  52. referencePeers := getPeersHelper(s3peers)
  53. if !reflect.DeepEqual(testCase.peers, referencePeers) {
  54. t.Errorf("Test %d: Expected %v, got %v", i+1, testCase.peers, referencePeers)
  55. }
  56. }
  57. }