sigs.k8s.io/cluster-api@v1.7.1/exp/topology/scope/scope_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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 25 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 26 ) 27 28 func TestNew(t *testing.T) { 29 t.Run("should set the right maxUpgradeConcurrency in UpgradeTracker from the cluster annotation", func(t *testing.T) { 30 tests := []struct { 31 name string 32 cluster *clusterv1.Cluster 33 want int 34 }{ 35 { 36 name: "if the annotation is not present the concurrency should default to 1", 37 cluster: &clusterv1.Cluster{}, 38 want: 1, 39 }, 40 { 41 name: "if the cluster has the annotation it should set the upgrade concurrency value", 42 cluster: &clusterv1.Cluster{ 43 ObjectMeta: metav1.ObjectMeta{ 44 Annotations: map[string]string{ 45 clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation: "2", 46 }, 47 }, 48 }, 49 want: 2, 50 }, 51 } 52 53 for _, tt := range tests { 54 g := NewWithT(t) 55 s := New(tt.cluster) 56 g.Expect(s.UpgradeTracker.MachineDeployments.maxUpgradeConcurrency).To(Equal(tt.want)) 57 g.Expect(s.UpgradeTracker.MachinePools.maxUpgradeConcurrency).To(Equal(tt.want)) 58 } 59 }) 60 }