sigs.k8s.io/cluster-api-provider-aws@v1.5.5/controlplane/eks/controllers/awsmanagedcontrolplane_controller_unit_test.go (about) 1 /* 2 Copyright 2022 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 controllers 18 19 import ( 20 "testing" 21 22 . "github.com/onsi/gomega" 23 24 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 25 ) 26 27 func TestSecurityGroupRolesForCluster(t *testing.T) { 28 tests := []struct { 29 name string 30 bastionEnabled bool 31 }{ 32 { 33 name: "Should use bastion security group when bastion is enabled", 34 bastionEnabled: true, 35 }, 36 { 37 name: "Should not use bastion security group when bastion is disabled", 38 bastionEnabled: false, 39 }, 40 } 41 42 for _, tt := range tests { 43 t.Run(tt.name, func(t *testing.T) { 44 g := NewWithT(t) 45 46 c := getAWSManagedControlPlane("test", "test") 47 c.Spec.Bastion.Enabled = tt.bastionEnabled 48 s, err := getManagedControlPlaneScope(c) 49 g.Expect(err).To(BeNil(), "failed to create cluster scope for test") 50 51 got := securityGroupRolesForControlPlane(s) 52 if tt.bastionEnabled { 53 g.Expect(got).To(ContainElement(infrav1.SecurityGroupBastion)) 54 } else { 55 g.Expect(got).ToNot(ContainElement(infrav1.SecurityGroupBastion)) 56 } 57 58 // Verify that function does not modify the package-level variable. 59 gotAgain := securityGroupRolesForControlPlane(s) 60 g.Expect(gotAgain).To(BeEquivalentTo(got), "two identical calls return different values") 61 }) 62 } 63 }