| 
 | 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 addons  | 
 | 18 | + | 
 | 19 | +import (  | 
 | 20 | +	"testing"  | 
 | 21 | + | 
 | 22 | +	"github.com/onsi/gomega"  | 
 | 23 | +)  | 
 | 24 | + | 
 | 25 | +func TestAddOnEqual(t *testing.T) {  | 
 | 26 | +	ptr := func(s string) *string { return &s }  | 
 | 27 | +	tags := func(s, t string) map[string]string {  | 
 | 28 | +		return map[string]string{  | 
 | 29 | +			s: t,  | 
 | 30 | +		}  | 
 | 31 | +	}  | 
 | 32 | +	g := gomega.NewGomegaWithT(t)  | 
 | 33 | +	tests := []struct {  | 
 | 34 | +		orig        *EKSAddon  | 
 | 35 | +		other       *EKSAddon  | 
 | 36 | +		result      gomega.OmegaMatcher  | 
 | 37 | +		includeTags bool  | 
 | 38 | +	}{  | 
 | 39 | +		{  | 
 | 40 | +			orig: &EKSAddon{  | 
 | 41 | +				Version:               ptr("a"),  | 
 | 42 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 43 | +				Configuration:         ptr("c"),  | 
 | 44 | +				ResolveConflict:       ptr("d"),  | 
 | 45 | +				Tags:                  tags("a", "1"),  | 
 | 46 | +			},  | 
 | 47 | +			other: &EKSAddon{  | 
 | 48 | +				Version:               ptr("a"),  | 
 | 49 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 50 | +				Configuration:         ptr("c"),  | 
 | 51 | +				ResolveConflict:       ptr("d"),  | 
 | 52 | +				Tags:                  tags("a", "1"),  | 
 | 53 | +				Status:                ptr("e"),  | 
 | 54 | +			},  | 
 | 55 | +			result: gomega.BeTrueBecause("addon values are equal (except status)"),  | 
 | 56 | +		},  | 
 | 57 | +		{  | 
 | 58 | +			orig: &EKSAddon{  | 
 | 59 | +				Version:               ptr("a"),  | 
 | 60 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 61 | +				Configuration:         ptr("c"),  | 
 | 62 | +			},  | 
 | 63 | +			other: &EKSAddon{  | 
 | 64 | +				Version:               ptr("b"),  | 
 | 65 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 66 | +				Configuration:         ptr("c"),  | 
 | 67 | +			},  | 
 | 68 | +			result: gomega.BeFalseBecause("addon version differs"),  | 
 | 69 | +		},  | 
 | 70 | +		{  | 
 | 71 | +			orig: &EKSAddon{  | 
 | 72 | +				Version:               ptr("a"),  | 
 | 73 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 74 | +				Configuration:         ptr("c"),  | 
 | 75 | +			},  | 
 | 76 | +			other: &EKSAddon{  | 
 | 77 | +				Version:               ptr("a"),  | 
 | 78 | +				ServiceAccountRoleARN: ptr("c"),  | 
 | 79 | +				Configuration:         ptr("c"),  | 
 | 80 | +			},  | 
 | 81 | +			result: gomega.BeFalseBecause("addon serviceAccountRoleARN differs"),  | 
 | 82 | +		},  | 
 | 83 | +		{  | 
 | 84 | +			orig: &EKSAddon{  | 
 | 85 | +				Version:               ptr("a"),  | 
 | 86 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 87 | +				Configuration:         ptr("c"),  | 
 | 88 | +			},  | 
 | 89 | +			other: &EKSAddon{  | 
 | 90 | +				Version:               ptr("a"),  | 
 | 91 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 92 | +				Configuration:         ptr("d"),  | 
 | 93 | +			},  | 
 | 94 | +			result: gomega.BeFalseBecause("addon configuration differs"),  | 
 | 95 | +		},  | 
 | 96 | +		{  | 
 | 97 | +			orig: &EKSAddon{  | 
 | 98 | +				Version:               ptr("a"),  | 
 | 99 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 100 | +				Configuration:         ptr("c"),  | 
 | 101 | +				ResolveConflict:       ptr("d"),  | 
 | 102 | +			},  | 
 | 103 | +			other: &EKSAddon{  | 
 | 104 | +				Version:               ptr("a"),  | 
 | 105 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 106 | +				Configuration:         ptr("d"),  | 
 | 107 | +				ResolveConflict:       ptr("e"),  | 
 | 108 | +			},  | 
 | 109 | +			result: gomega.BeFalseBecause("addon conflict resolution differs"),  | 
 | 110 | +		},  | 
 | 111 | +		{  | 
 | 112 | +			orig: &EKSAddon{  | 
 | 113 | +				Version:               ptr("a"),  | 
 | 114 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 115 | +				Tags:                  tags("a", "1"),  | 
 | 116 | +			},  | 
 | 117 | +			other: &EKSAddon{  | 
 | 118 | +				Version:               ptr("a"),  | 
 | 119 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 120 | +				Tags:                  tags("a", "2"),  | 
 | 121 | +			},  | 
 | 122 | +			result: gomega.BeTrueBecause("addon tags differ but not used for comparison"),  | 
 | 123 | +		},  | 
 | 124 | +		{  | 
 | 125 | +			orig: &EKSAddon{  | 
 | 126 | +				Version:               ptr("a"),  | 
 | 127 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 128 | +				Tags:                  tags("a", "1"),  | 
 | 129 | +			},  | 
 | 130 | +			other: &EKSAddon{  | 
 | 131 | +				Version:               ptr("a"),  | 
 | 132 | +				ServiceAccountRoleARN: ptr("b"),  | 
 | 133 | +				Tags:                  tags("a", "2"),  | 
 | 134 | +			},  | 
 | 135 | +			result:      gomega.BeFalseBecause("addon tags differ and used for comparison"),  | 
 | 136 | +			includeTags: true,  | 
 | 137 | +		},  | 
 | 138 | +	}  | 
 | 139 | + | 
 | 140 | +	for _, test := range tests {  | 
 | 141 | +		g.Expect(test.orig.IsEqual(test.other, test.includeTags)).To(test.result)  | 
 | 142 | +	}  | 
 | 143 | +}  | 
0 commit comments