github.com/minio/madmin-go@v1.7.5/heal-commands_test.go (about) 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 17 package madmin 18 19 import ( 20 "testing" 21 ) 22 23 // Tests heal drives missing and offline counts. 24 func TestHealDriveCounts(t *testing.T) { 25 rs := HealResultItem{} 26 rs.Before.Drives = make([]HealDriveInfo, 20) 27 rs.After.Drives = make([]HealDriveInfo, 20) 28 for i := range rs.Before.Drives { 29 if i < 4 { 30 rs.Before.Drives[i] = HealDriveInfo{State: DriveStateMissing} 31 rs.After.Drives[i] = HealDriveInfo{State: DriveStateMissing} 32 } else if i > 4 && i < 15 { 33 rs.Before.Drives[i] = HealDriveInfo{State: DriveStateOffline} 34 rs.After.Drives[i] = HealDriveInfo{State: DriveStateOffline} 35 } else if i > 15 { 36 rs.Before.Drives[i] = HealDriveInfo{State: DriveStateCorrupt} 37 rs.After.Drives[i] = HealDriveInfo{State: DriveStateCorrupt} 38 } else { 39 rs.Before.Drives[i] = HealDriveInfo{State: DriveStateOk} 40 rs.After.Drives[i] = HealDriveInfo{State: DriveStateOk} 41 } 42 } 43 44 i, j := rs.GetOnlineCounts() 45 if i > 2 { 46 t.Errorf("Expected '2', got %d before online disks", i) 47 } 48 if j > 2 { 49 t.Errorf("Expected '2', got %d after online disks", j) 50 } 51 i, j = rs.GetOfflineCounts() 52 if i > 10 { 53 t.Errorf("Expected '10', got %d before offline disks", i) 54 } 55 if j > 10 { 56 t.Errorf("Expected '10', got %d after offline disks", j) 57 } 58 i, j = rs.GetCorruptedCounts() 59 if i > 4 { 60 t.Errorf("Expected '4', got %d before corrupted disks", i) 61 } 62 if j > 4 { 63 t.Errorf("Expected '4', got %d after corrupted disks", j) 64 } 65 i, j = rs.GetMissingCounts() 66 if i > 4 { 67 t.Errorf("Expected '4', got %d before missing disks", i) 68 } 69 if j > 4 { 70 t.Errorf("Expected '4', got %d after missing disks", i) 71 } 72 }