|
| 1 | +package shared_utils |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2" |
| 8 | +) |
| 9 | + |
| 10 | +func TestMakeLoadBalancerAttributeSliceFromMap(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + attributeMap map[string]string |
| 14 | + expected []elbv2model.LoadBalancerAttribute |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "empty map", |
| 18 | + attributeMap: map[string]string{}, |
| 19 | + expected: []elbv2model.LoadBalancerAttribute{}, |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "single attribute", |
| 23 | + attributeMap: map[string]string{"key1": "value1"}, |
| 24 | + expected: []elbv2model.LoadBalancerAttribute{{Key: "key1", Value: "value1"}}, |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "multiple attributes", |
| 28 | + attributeMap: map[string]string{"key2": "value2", "key1": "value1", "key3": "value3"}, |
| 29 | + expected: []elbv2model.LoadBalancerAttribute{ |
| 30 | + {Key: "key1", Value: "value1"}, |
| 31 | + {Key: "key2", Value: "value2"}, |
| 32 | + {Key: "key3", Value: "value3"}, |
| 33 | + }, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "attributes with special characters", |
| 37 | + attributeMap: map[string]string{"key-with-dash": "value with spaces", "key_with_underscore": "value=with=equals"}, |
| 38 | + expected: []elbv2model.LoadBalancerAttribute{ |
| 39 | + {Key: "key-with-dash", Value: "value with spaces"}, |
| 40 | + {Key: "key_with_underscore", Value: "value=with=equals"}, |
| 41 | + }, |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + for _, tt := range tests { |
| 46 | + t.Run(tt.name, func(t *testing.T) { |
| 47 | + result := MakeLoadBalancerAttributeSliceFromMap(tt.attributeMap) |
| 48 | + assert.Equal(t, tt.expected, result) |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func TestMakeLoadBalancerAttributeSliceFromMap_Sorting(t *testing.T) { |
| 54 | + // Test that attributes are properly sorted by key |
| 55 | + attributeMap := map[string]string{ |
| 56 | + "zebra": "last", |
| 57 | + "apple": "first", |
| 58 | + "banana": "middle", |
| 59 | + } |
| 60 | + |
| 61 | + result := MakeLoadBalancerAttributeSliceFromMap(attributeMap) |
| 62 | + |
| 63 | + expected := []elbv2model.LoadBalancerAttribute{ |
| 64 | + {Key: "apple", Value: "first"}, |
| 65 | + {Key: "banana", Value: "middle"}, |
| 66 | + {Key: "zebra", Value: "last"}, |
| 67 | + } |
| 68 | + |
| 69 | + assert.Equal(t, expected, result) |
| 70 | +} |
0 commit comments