sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1alpha4/types_test.go (about) 1 /* 2 Copyright 2021 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 v1alpha4 18 19 import ( 20 "testing" 21 22 . "github.com/onsi/gomega" 23 ) 24 25 func TestSG_Difference(t *testing.T) { 26 tests := []struct { 27 name string 28 self IngressRules 29 input IngressRules 30 expected IngressRules 31 }{ 32 { 33 name: "self and input are nil", 34 self: nil, 35 input: nil, 36 expected: nil, 37 }, 38 { 39 name: "input is nil", 40 self: IngressRules{ 41 { 42 Description: "SSH", 43 Protocol: SecurityGroupProtocolTCP, 44 FromPort: 22, 45 ToPort: 22, 46 SourceSecurityGroupIDs: []string{"sg-source-1"}, 47 }, 48 }, 49 input: nil, 50 expected: IngressRules{ 51 { 52 Description: "SSH", 53 Protocol: SecurityGroupProtocolTCP, 54 FromPort: 22, 55 ToPort: 22, 56 SourceSecurityGroupIDs: []string{"sg-source-1"}, 57 }, 58 }, 59 }, 60 { 61 name: "self has more rules", 62 self: IngressRules{ 63 { 64 Description: "SSH", 65 Protocol: SecurityGroupProtocolTCP, 66 FromPort: 22, 67 ToPort: 22, 68 SourceSecurityGroupIDs: []string{"sg-source-1"}, 69 }, 70 { 71 Description: "MY-SSH", 72 Protocol: SecurityGroupProtocolTCP, 73 FromPort: 22, 74 ToPort: 22, 75 CidrBlocks: []string{"0.0.0.0/0"}, 76 }, 77 }, 78 input: IngressRules{ 79 { 80 Description: "SSH", 81 Protocol: SecurityGroupProtocolTCP, 82 FromPort: 22, 83 ToPort: 22, 84 SourceSecurityGroupIDs: []string{"sg-source-1"}, 85 }, 86 }, 87 expected: IngressRules{ 88 { 89 Description: "MY-SSH", 90 Protocol: SecurityGroupProtocolTCP, 91 FromPort: 22, 92 ToPort: 22, 93 CidrBlocks: []string{"0.0.0.0/0"}, 94 }, 95 }, 96 }, 97 } 98 99 for _, tc := range tests { 100 t.Run(tc.name, func(t *testing.T) { 101 g := NewGomegaWithT(t) 102 out := tc.self.Difference(tc.input) 103 104 g.Expect(out).To(Equal(tc.expected)) 105 }) 106 } 107 }