storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/madmin/heal-commands_test.go (about)

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