Skip to content

Commit

Permalink
Add watchutil test to ensure ir.Xds is compared properly
Browse files Browse the repository at this point in the history
Signed-off-by: David Boslee <david@goteleport.com>
  • Loading branch information
dboslee committed Aug 17, 2023
1 parent 6b4d5ac commit a1bdeb2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions internal/message/watchutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/telepresenceio/watchable"

"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/message"
)

Expand Down Expand Up @@ -59,3 +60,67 @@ func TestHandleSubscriptionAlreadyInitialized(t *testing.T) {
assert.Equal(t, 2, storeCalls)
assert.Equal(t, 1, deleteCalls)
}

func TestXdsIRUpdates(t *testing.T) {
tests := []struct {
desc string
xx []*ir.Xds
updates int
}{
{
desc: "HTTP listener order change skips update",
xx: []*ir.Xds{
{
HTTP: []*ir.HTTPListener{
{Name: "listener-1"},
{Name: "listener-2"},
},
},
{
HTTP: []*ir.HTTPListener{
{Name: "listener-2"},
{Name: "listener-1"},
},
},
},
updates: 1,
},
{
desc: "Additional HTTP listener triggers update",
xx: []*ir.Xds{
{
HTTP: []*ir.HTTPListener{
{Name: "listener-1"},
},
},
{
HTTP: []*ir.HTTPListener{
{Name: "listener-1"},
{Name: "listener-2"},
},
},
},
updates: 2,
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
ctx := context.Background()
m := new(message.XdsIR)

snapshotC := m.Subscribe(ctx)
go func() {
for _, x := range tc.xx {
m.Store("test", x)
}
m.Close()
}()

updates := 0
message.HandleSubscription(snapshotC, func(u message.Update[string, *ir.Xds]) {
updates += 1
})
assert.Equal(t, tc.updates, updates)
})
}
}

0 comments on commit a1bdeb2

Please sign in to comment.