|
| 1 | +package elbv2 |
| 2 | + |
| 3 | +import ( |
| 4 | + awssdk "github.com/aws/aws-sdk-go-v2/aws" |
| 5 | + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types" |
| 6 | + "github.com/google/go-cmp/cmp" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +func Test_CompareOptionForRuleConditions(t *testing.T) { |
| 12 | + testCase := []struct { |
| 13 | + name string |
| 14 | + desiredRuleCondition []types.RuleCondition |
| 15 | + actualRuleCondition []types.RuleCondition |
| 16 | + expected bool |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "equal", |
| 20 | + desiredRuleCondition: []types.RuleCondition{ |
| 21 | + { |
| 22 | + Field: awssdk.String("host-header"), |
| 23 | + HostHeaderConfig: &types.HostHeaderConditionConfig{ |
| 24 | + Values: []string{"h1"}, |
| 25 | + }, |
| 26 | + }, |
| 27 | + { |
| 28 | + Field: awssdk.String("path-pattern"), |
| 29 | + PathPatternConfig: &types.PathPatternConditionConfig{ |
| 30 | + Values: []string{"path-pattern"}, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + actualRuleCondition: []types.RuleCondition{ |
| 35 | + { |
| 36 | + Field: awssdk.String("host-header"), |
| 37 | + HostHeaderConfig: &types.HostHeaderConditionConfig{ |
| 38 | + Values: []string{"h1"}, |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + Field: awssdk.String("path-pattern"), |
| 43 | + PathPatternConfig: &types.PathPatternConditionConfig{ |
| 44 | + Values: []string{"path-pattern"}, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + expected: true, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "equal - different order", |
| 52 | + desiredRuleCondition: []types.RuleCondition{ |
| 53 | + { |
| 54 | + Field: awssdk.String("host-header"), |
| 55 | + HostHeaderConfig: &types.HostHeaderConditionConfig{ |
| 56 | + Values: []string{"h1"}, |
| 57 | + }, |
| 58 | + }, |
| 59 | + { |
| 60 | + Field: awssdk.String("path-pattern"), |
| 61 | + PathPatternConfig: &types.PathPatternConditionConfig{ |
| 62 | + Values: []string{"path-pattern"}, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + actualRuleCondition: []types.RuleCondition{ |
| 67 | + { |
| 68 | + Field: awssdk.String("path-pattern"), |
| 69 | + PathPatternConfig: &types.PathPatternConditionConfig{ |
| 70 | + Values: []string{"path-pattern"}, |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + Field: awssdk.String("host-header"), |
| 75 | + HostHeaderConfig: &types.HostHeaderConditionConfig{ |
| 76 | + Values: []string{"h1"}, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + expected: true, |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + for _, tc := range testCase { |
| 85 | + t.Run(tc.name, func(t *testing.T) { |
| 86 | + conditionsEqual := cmp.Equal(tc.desiredRuleCondition, tc.actualRuleCondition, CompareOptionForRuleConditions(nil, nil)) |
| 87 | + assert.Equal(t, tc.expected, conditionsEqual) |
| 88 | + }) |
| 89 | + } |
| 90 | +} |
0 commit comments