github.com/minio/madmin-go/v2@v2.2.1/heal-commands_test.go (about)

     1  //
     2  // Copyright (c) 2015-2022 MinIO, Inc.
     3  //
     4  // This file is part of MinIO Object Storage stack
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as
     8  // published by the Free Software Foundation, either version 3 of the
     9  // License, or (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package madmin
    21  
    22  import (
    23  	"testing"
    24  )
    25  
    26  // Tests heal drives missing and offline counts.
    27  func TestHealDriveCounts(t *testing.T) {
    28  	rs := HealResultItem{}
    29  	rs.Before.Drives = make([]HealDriveInfo, 20)
    30  	rs.After.Drives = make([]HealDriveInfo, 20)
    31  	for i := range rs.Before.Drives {
    32  		if i < 4 {
    33  			rs.Before.Drives[i] = HealDriveInfo{State: DriveStateMissing}
    34  			rs.After.Drives[i] = HealDriveInfo{State: DriveStateMissing}
    35  		} else if i > 4 && i < 15 {
    36  			rs.Before.Drives[i] = HealDriveInfo{State: DriveStateOffline}
    37  			rs.After.Drives[i] = HealDriveInfo{State: DriveStateOffline}
    38  		} else if i > 15 {
    39  			rs.Before.Drives[i] = HealDriveInfo{State: DriveStateCorrupt}
    40  			rs.After.Drives[i] = HealDriveInfo{State: DriveStateCorrupt}
    41  		} else {
    42  			rs.Before.Drives[i] = HealDriveInfo{State: DriveStateOk}
    43  			rs.After.Drives[i] = HealDriveInfo{State: DriveStateOk}
    44  		}
    45  	}
    46  
    47  	i, j := rs.GetOnlineCounts()
    48  	if i > 2 {
    49  		t.Errorf("Expected '2', got %d before online disks", i)
    50  	}
    51  	if j > 2 {
    52  		t.Errorf("Expected '2', got %d after online disks", j)
    53  	}
    54  	i, j = rs.GetOfflineCounts()
    55  	if i > 10 {
    56  		t.Errorf("Expected '10', got %d before offline disks", i)
    57  	}
    58  	if j > 10 {
    59  		t.Errorf("Expected '10', got %d after offline disks", j)
    60  	}
    61  	i, j = rs.GetCorruptedCounts()
    62  	if i > 4 {
    63  		t.Errorf("Expected '4', got %d before corrupted disks", i)
    64  	}
    65  	if j > 4 {
    66  		t.Errorf("Expected '4', got %d after corrupted disks", j)
    67  	}
    68  	i, j = rs.GetMissingCounts()
    69  	if i > 4 {
    70  		t.Errorf("Expected '4', got %d before missing disks", i)
    71  	}
    72  	if j > 4 {
    73  		t.Errorf("Expected '4', got %d after missing disks", i)
    74  	}
    75  }