|
| 1 | +// Copyright Envoy Gateway Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +// The full text of the Apache license is available in the LICENSE file at |
| 4 | +// the root of the repo. |
| 5 | + |
| 6 | +package message_test |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "fmt" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | + |
| 15 | + egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" |
| 16 | + "github.com/envoyproxy/gateway/internal/ir" |
| 17 | + "github.com/envoyproxy/gateway/internal/message" |
| 18 | +) |
| 19 | + |
| 20 | +// XdsIRWithContext structs with differing context values should be Equal |
| 21 | +func TestXdsWithContextEqual(t *testing.T) { |
| 22 | + xdsIR := &ir.Xds{ |
| 23 | + HTTP: []*ir.HTTPListener{ |
| 24 | + { |
| 25 | + CoreListenerDetails: ir.CoreListenerDetails{ |
| 26 | + Name: fmt.Sprintf("default/%s/listener-0", "gwName"), |
| 27 | + }, |
| 28 | + Routes: []*ir.HTTPRoute{ |
| 29 | + { |
| 30 | + Name: "route-0", |
| 31 | + Traffic: &ir.TrafficFeatures{ |
| 32 | + RateLimit: &ir.RateLimit{ |
| 33 | + Global: &ir.GlobalRateLimit{ |
| 34 | + Rules: []*ir.RateLimitRule{ |
| 35 | + { |
| 36 | + HeaderMatches: []*ir.StringMatch{ |
| 37 | + { |
| 38 | + Name: "x-user-id", |
| 39 | + Distinct: true, |
| 40 | + }, |
| 41 | + }, |
| 42 | + Limit: ir.RateLimitValue{ |
| 43 | + Requests: 100, |
| 44 | + Unit: ir.RateLimitUnit(egv1a1.RateLimitUnitMinute), |
| 45 | + }, |
| 46 | + }, |
| 47 | + { |
| 48 | + HeaderMatches: []*ir.StringMatch{ |
| 49 | + { |
| 50 | + Name: "x-another-user-id", |
| 51 | + Distinct: true, |
| 52 | + }, |
| 53 | + }, |
| 54 | + Limit: ir.RateLimitValue{ |
| 55 | + Requests: 10, |
| 56 | + Unit: ir.RateLimitUnit(egv1a1.RateLimitUnitSecond), |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + c1 := context.Background() |
| 70 | + c2 := context.TODO() |
| 71 | + |
| 72 | + x1 := &message.XdsIRWithContext{ |
| 73 | + XdsIR: xdsIR, |
| 74 | + Context: c1, |
| 75 | + } |
| 76 | + x2 := &message.XdsIRWithContext{ |
| 77 | + XdsIR: xdsIR, |
| 78 | + Context: c2, |
| 79 | + } |
| 80 | + |
| 81 | + assert.True(t, x1.Equal(x2)) |
| 82 | + assert.True(t, x2.Equal(x1)) |
| 83 | +} |
0 commit comments