sigs.k8s.io/cluster-api@v1.7.1/exp/topology/scope/upgradetracker_test.go (about)

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     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 scope
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "github.com/onsi/gomega"
    23  )
    24  
    25  func TestNewUpgradeTracker(t *testing.T) {
    26  	t.Run("should set the correct value for maxUpgradeConcurrency", func(t *testing.T) {
    27  		tests := []struct {
    28  			name    string
    29  			options []UpgradeTrackerOption
    30  			want    int
    31  		}{
    32  			{
    33  				name:    "should set a default value of 1 if not concurrency is not specified",
    34  				options: nil,
    35  				want:    1,
    36  			},
    37  			{
    38  				name:    "should set the value of 1 if given concurrency is less than 1",
    39  				options: []UpgradeTrackerOption{MaxMDUpgradeConcurrency(0), MaxMPUpgradeConcurrency(0)},
    40  				want:    1,
    41  			},
    42  			{
    43  				name:    "should set the value to the given concurrency if the value is greater than 0",
    44  				options: []UpgradeTrackerOption{MaxMDUpgradeConcurrency(2), MaxMPUpgradeConcurrency(2)},
    45  				want:    2,
    46  			},
    47  		}
    48  
    49  		for _, tt := range tests {
    50  			g := NewWithT(t)
    51  			got := NewUpgradeTracker(tt.options...)
    52  			g.Expect(got.MachineDeployments.maxUpgradeConcurrency).To(Equal(tt.want))
    53  			g.Expect(got.MachinePools.maxUpgradeConcurrency).To(Equal(tt.want))
    54  		}
    55  	})
    56  }