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.

114 lines
2.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 main
  17. import "testing"
  18. // Collection of disks verbatim used for tests.
  19. var disks = []string{
  20. "/mnt/backend1",
  21. "/mnt/backend2",
  22. "/mnt/backend3",
  23. "/mnt/backend4",
  24. "/mnt/backend5",
  25. "/mnt/backend6",
  26. "/mnt/backend7",
  27. "/mnt/backend8",
  28. "/mnt/backend9",
  29. "/mnt/backend10",
  30. "/mnt/backend11",
  31. "/mnt/backend12",
  32. "/mnt/backend13",
  33. "/mnt/backend14",
  34. "/mnt/backend15",
  35. "/mnt/backend16",
  36. }
  37. // Tests all the expected input disks for function checkSufficientDisks.
  38. func TestCheckSufficientDisks(t *testing.T) {
  39. // List of test cases fo sufficient disk verification.
  40. testCases := []struct {
  41. disks []string
  42. expectedErr error
  43. }{
  44. // Even number of disks '8'.
  45. {
  46. disks[0:8],
  47. nil,
  48. },
  49. // Even number of disks '12'.
  50. {
  51. disks[0:12],
  52. nil,
  53. },
  54. // Even number of disks '16'.
  55. {
  56. disks[0:16],
  57. nil,
  58. },
  59. // Larger than maximum number of disks > 16.
  60. {
  61. append(disks[0:16], "/mnt/unsupported"),
  62. errXLMaxDisks,
  63. },
  64. // Lesser than minimum number of disks < 8.
  65. {
  66. disks[0:7],
  67. errXLMinDisks,
  68. },
  69. // Odd number of disks, not divisible by '2'.
  70. {
  71. append(disks[0:10], disks[11]),
  72. errXLNumDisks,
  73. },
  74. }
  75. // Validates different variations of input disks.
  76. for i, testCase := range testCases {
  77. if checkSufficientDisks(testCase.disks) != testCase.expectedErr {
  78. t.Errorf("Test %d expected to pass for disks %s", i+1, testCase.disks)
  79. }
  80. }
  81. }
  82. // TestStorageInfo - tests storage info.
  83. func TestStorageInfo(t *testing.T) {
  84. objLayer, fsDirs, err := getXLObjectLayer()
  85. if err != nil {
  86. t.Fatalf("Unable to initialize 'XL' object layer.")
  87. }
  88. // Remove all dirs.
  89. for _, dir := range fsDirs {
  90. defer removeAll(dir)
  91. }
  92. // Get storage info first attempt.
  93. disks16Info := objLayer.StorageInfo()
  94. // This test assumes homogenity between all disks,
  95. // i.e if we loose one disk the effective storage
  96. // usage values is assumed to decrease. If we have
  97. // heterogenous environment this is not true all the time.
  98. if disks16Info.Free <= 0 {
  99. t.Fatalf("Diskinfo total free values should be greater 0")
  100. }
  101. if disks16Info.Total <= 0 {
  102. t.Fatalf("Diskinfo total values should be greater 0")
  103. }
  104. }