|
| 1 | +package shared_utils |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2" |
| 8 | +) |
| 9 | + |
| 10 | +func TestMakeAttributesSliceFromMap(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + input map[string]string |
| 14 | + want []elbv2model.LoadBalancerAttribute |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "empty map", |
| 18 | + input: map[string]string{}, |
| 19 | + want: []elbv2model.LoadBalancerAttribute{}, |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "single attribute", |
| 23 | + input: map[string]string{ |
| 24 | + "key1": "value1", |
| 25 | + }, |
| 26 | + want: []elbv2model.LoadBalancerAttribute{ |
| 27 | + {Key: "key1", Value: "value1"}, |
| 28 | + }, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "multiple attributes, unordered input", |
| 32 | + input: map[string]string{ |
| 33 | + "zeta": "last", |
| 34 | + "alpha": "first", |
| 35 | + "mid": "middle", |
| 36 | + }, |
| 37 | + want: []elbv2model.LoadBalancerAttribute{ |
| 38 | + {Key: "alpha", Value: "first"}, |
| 39 | + {Key: "mid", Value: "middle"}, |
| 40 | + {Key: "zeta", Value: "last"}, |
| 41 | + }, |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + for _, tt := range tests { |
| 46 | + t.Run(tt.name, func(t *testing.T) { |
| 47 | + got := MakeAttributesSliceFromMap(tt.input) |
| 48 | + if !reflect.DeepEqual(got, tt.want) { |
| 49 | + t.Errorf("MakeAttributesSliceFromMap() = %v, want %v", got, tt.want) |
| 50 | + } |
| 51 | + }) |
| 52 | + } |
| 53 | +} |
0 commit comments