github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/site-replication_test.go (about)

     1  // Copyright (c) 2015-2021 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/minio/madmin-go/v3"
    24  	"github.com/minio/minio-go/v7/pkg/set"
    25  )
    26  
    27  // TestGetMissingSiteNames
    28  func TestGetMissingSiteNames(t *testing.T) {
    29  	testCases := []struct {
    30  		currSites []madmin.PeerInfo
    31  		oldDepIDs set.StringSet
    32  		newDepIDs set.StringSet
    33  		expNames  []string
    34  	}{
    35  		// Test1: missing some sites in replicated setup
    36  		{
    37  			[]madmin.PeerInfo{
    38  				{Endpoint: "minio1:9000", Name: "minio1", DeploymentID: "dep1"},
    39  				{Endpoint: "minio2:9000", Name: "minio2", DeploymentID: "dep2"},
    40  				{Endpoint: "minio3:9000", Name: "minio3", DeploymentID: "dep3"},
    41  			},
    42  			set.CreateStringSet("dep1", "dep2", "dep3"),
    43  			set.CreateStringSet("dep1"),
    44  			[]string{"minio2", "minio3"},
    45  		},
    46  		// Test2: new site added that is not in replicated setup
    47  		{
    48  			[]madmin.PeerInfo{{Endpoint: "minio1:9000", Name: "minio1", DeploymentID: "dep1"}, {Endpoint: "minio2:9000", Name: "minio2", DeploymentID: "dep2"}, {Endpoint: "minio3:9000", Name: "minio3", DeploymentID: "dep3"}},
    49  			set.CreateStringSet("dep1", "dep2", "dep3"),
    50  			set.CreateStringSet("dep1", "dep2", "dep3", "dep4"),
    51  			[]string{},
    52  		},
    53  		// Test3: not currently under site replication.
    54  		{
    55  			[]madmin.PeerInfo{},
    56  			set.CreateStringSet(),
    57  			set.CreateStringSet("dep1", "dep2", "dep3", "dep4"),
    58  			[]string{},
    59  		},
    60  	}
    61  
    62  	for i, tc := range testCases {
    63  		names := getMissingSiteNames(tc.oldDepIDs, tc.newDepIDs, tc.currSites)
    64  		if len(names) != len(tc.expNames) {
    65  			t.Errorf("Test %d: Expected `%v`, got `%v`", i+1, tc.expNames, names)
    66  		}
    67  	}
    68  }