2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2023-02-17 21:14:46 +00:00
|
|
|
"github.com/hashicorp/consul/proto/private/pbsubscribe"
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigEntryEventsFromChanges(t *testing.T) {
|
|
|
|
const changeIndex uint64 = 123
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
setup func(tx *txn) error
|
|
|
|
mutate func(tx *txn) error
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"upsert mesh config": {
|
|
|
|
mutate: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.MeshConfigEntry{
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
Meta: map[string]string{"foo": "bar"},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicMeshConfig,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: &structs.MeshConfigEntry{
|
|
|
|
Meta: map[string]string{"foo": "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"delete mesh config": {
|
|
|
|
setup: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.MeshConfigEntry{})
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
},
|
|
|
|
mutate: func(tx *txn) error {
|
|
|
|
return deleteConfigEntryTxn(tx, 0, structs.MeshConfig, structs.MeshConfigMesh, nil)
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicMeshConfig,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Delete,
|
|
|
|
Value: &structs.MeshConfigEntry{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"upsert service resolver": {
|
|
|
|
mutate: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceResolverConfigEntry{
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceResolver,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: &structs.ServiceResolverConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"delete service resolver": {
|
|
|
|
setup: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceResolverConfigEntry{
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
mutate: func(tx *txn) error {
|
|
|
|
return deleteConfigEntryTxn(tx, 0, structs.ServiceResolver, "web", nil)
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceResolver,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Delete,
|
|
|
|
Value: &structs.ServiceResolverConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"upsert ingress gateway": {
|
|
|
|
mutate: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.IngressGatewayConfigEntry{
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
Name: "gw1",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicIngressGateway,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: &structs.IngressGatewayConfigEntry{
|
|
|
|
Name: "gw1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"delete ingress gateway": {
|
|
|
|
setup: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.IngressGatewayConfigEntry{
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
Name: "gw1",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
mutate: func(tx *txn) error {
|
|
|
|
return deleteConfigEntryTxn(tx, 0, structs.IngressGateway, "gw1", nil)
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicIngressGateway,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Delete,
|
|
|
|
Value: &structs.IngressGatewayConfigEntry{
|
|
|
|
Name: "gw1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-01 15:15:49 +00:00
|
|
|
"upsert service intentions": {
|
|
|
|
mutate: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceIntentionsConfigEntry{
|
2022-07-01 15:15:49 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceIntentions,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"delete service intentions": {
|
|
|
|
setup: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceIntentionsConfigEntry{
|
2022-07-01 15:15:49 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
mutate: func(tx *txn) error {
|
|
|
|
return deleteConfigEntryTxn(tx, 0, structs.ServiceIntentions, "web", nil)
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceIntentions,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Delete,
|
|
|
|
Value: &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-24 18:50:28 +00:00
|
|
|
"upsert service defaults": {
|
|
|
|
mutate: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceConfigEntry{
|
2022-10-24 18:50:28 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceDefaults,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: &structs.ServiceConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"delete service defaults": {
|
|
|
|
setup: func(tx *txn) error {
|
2023-01-27 19:34:11 +00:00
|
|
|
return ensureConfigEntryTxn(tx, 0, false, &structs.ServiceConfigEntry{
|
2022-10-24 18:50:28 +00:00
|
|
|
Name: "web",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
mutate: func(tx *txn) error {
|
|
|
|
return deleteConfigEntryTxn(tx, 0, structs.ServiceDefaults, "web", nil)
|
|
|
|
},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceDefaults,
|
|
|
|
Index: changeIndex,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Delete,
|
|
|
|
Value: &structs.ServiceConfigEntry{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
}
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
store := testStateStore(t)
|
|
|
|
|
|
|
|
if tc.setup != nil {
|
|
|
|
tx := store.db.WriteTxn(0)
|
|
|
|
require.NoError(t, tc.setup(tx))
|
|
|
|
require.NoError(t, tx.Commit())
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := store.db.WriteTxn(0)
|
|
|
|
t.Cleanup(tx.Abort)
|
|
|
|
|
|
|
|
if tc.mutate != nil {
|
|
|
|
require.NoError(t, tc.mutate(tx))
|
|
|
|
}
|
|
|
|
|
|
|
|
events, err := ConfigEntryEventsFromChanges(tx, Changes{Index: changeIndex, Changes: tx.Changes()})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.events, events)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMeshConfigSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
entry := &structs.MeshConfigEntry{
|
|
|
|
Meta: map[string]string{"foo": "bar"},
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, entry))
|
|
|
|
|
|
|
|
testCases := map[string]stream.Subject{
|
|
|
|
"named entry": EventSubjectConfigEntry{Name: structs.MeshConfigMesh},
|
|
|
|
"wildcard": stream.SubjectWildcard,
|
|
|
|
}
|
|
|
|
for desc, subject := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.MeshConfigSnapshot(stream.SubscribeRequest{Subject: subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.Len(t, buf.events[0], 1)
|
|
|
|
|
|
|
|
payload := buf.events[0][0].Payload.(EventPayloadConfigEntry)
|
|
|
|
require.Equal(t, pbsubscribe.ConfigEntryUpdate_Upsert, payload.Op)
|
|
|
|
require.Equal(t, entry, payload.Value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServiceResolverSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
webResolver := &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
}
|
|
|
|
dbResolver := &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, webResolver))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, dbResolver))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: "web"},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceResolver,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: webResolver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceResolver,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: webResolver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceResolver,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: dbResolver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.ServiceResolverSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIngressGatewaySnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
gw1 := &structs.IngressGatewayConfigEntry{
|
|
|
|
Kind: structs.IngressGateway,
|
|
|
|
Name: "gw1",
|
|
|
|
}
|
|
|
|
gw2 := &structs.IngressGatewayConfigEntry{
|
|
|
|
Kind: structs.IngressGateway,
|
|
|
|
Name: "gw2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: gw1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicIngressGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicIngressGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicIngressGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.IngressGatewaySnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 15:15:49 +00:00
|
|
|
|
|
|
|
func TestServiceIntentionsSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
ixn1 := &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
2022-10-24 18:50:28 +00:00
|
|
|
Name: "svc1",
|
2022-07-01 15:15:49 +00:00
|
|
|
}
|
|
|
|
ixn2 := &structs.ServiceIntentionsConfigEntry{
|
|
|
|
Kind: structs.ServiceIntentions,
|
2022-10-24 18:50:28 +00:00
|
|
|
Name: "svc2",
|
2022-07-01 15:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, ixn1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, ixn2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: ixn1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceIntentions,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceIntentions,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceIntentions,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.ServiceIntentionsSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-10-24 18:50:28 +00:00
|
|
|
|
|
|
|
func TestServiceDefaultsSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
ixn1 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "svc1",
|
|
|
|
}
|
|
|
|
ixn2 := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "svc2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, ixn1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, ixn2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: ixn1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceDefaults,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceDefaults,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicServiceDefaults,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: ixn2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.ServiceDefaultsSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-01-18 22:14:34 +00:00
|
|
|
|
|
|
|
func TestAPIGatewaySnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
gw1 := &structs.APIGatewayConfigEntry{
|
|
|
|
Kind: structs.APIGateway,
|
|
|
|
Name: "agw1",
|
|
|
|
}
|
|
|
|
gw2 := &structs.APIGatewayConfigEntry{
|
|
|
|
Kind: structs.APIGateway,
|
|
|
|
Name: "agw2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: gw1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.APIGatewaySnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTCPRouteSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
rt1 := &structs.TCPRouteConfigEntry{
|
|
|
|
Kind: structs.TCPRoute,
|
|
|
|
Name: "tcprt1",
|
|
|
|
}
|
|
|
|
rt2 := &structs.TCPRouteConfigEntry{
|
|
|
|
Kind: structs.TCPRoute,
|
|
|
|
Name: "tcprt2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, rt1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, rt2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: rt1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicTCPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: rt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicTCPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: rt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicTCPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: rt2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.TCPRouteSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPRouteSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
rt1 := &structs.HTTPRouteConfigEntry{
|
|
|
|
Kind: structs.HTTPRoute,
|
|
|
|
Name: "httprt1",
|
|
|
|
}
|
|
|
|
gw2 := &structs.HTTPRouteConfigEntry{
|
|
|
|
Kind: structs.HTTPRoute,
|
|
|
|
Name: "httprt2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, rt1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: rt1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicHTTPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: rt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicHTTPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: rt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicHTTPRoute,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.HTTPRouteSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInlineCertificateSnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
crt1 := &structs.InlineCertificateConfigEntry{
|
|
|
|
Kind: structs.InlineCertificate,
|
|
|
|
Name: "inlinecert1",
|
|
|
|
}
|
|
|
|
crt2 := &structs.InlineCertificateConfigEntry{
|
|
|
|
Kind: structs.InlineCertificate,
|
|
|
|
Name: "inlinecert2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, crt1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, crt2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: crt1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicInlineCertificate,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: crt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicInlineCertificate,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: crt1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicInlineCertificate,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: crt2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.InlineCertificateSnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBoundAPIGatewaySnapshot(t *testing.T) {
|
|
|
|
const index uint64 = 123
|
|
|
|
|
|
|
|
gw1 := &structs.BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: structs.BoundAPIGateway,
|
|
|
|
Name: "boundapigw1",
|
|
|
|
}
|
|
|
|
gw2 := &structs.BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: structs.BoundAPIGateway,
|
|
|
|
Name: "boundapigw2",
|
|
|
|
}
|
|
|
|
|
|
|
|
store := testStateStore(t)
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw1))
|
|
|
|
require.NoError(t, store.EnsureConfigEntry(index, gw2))
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
subject stream.Subject
|
|
|
|
events []stream.Event
|
|
|
|
}{
|
|
|
|
"named entry": {
|
|
|
|
subject: EventSubjectConfigEntry{Name: gw1.Name},
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicBoundAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"wildcard": {
|
|
|
|
subject: stream.SubjectWildcard,
|
|
|
|
events: []stream.Event{
|
|
|
|
{
|
|
|
|
Topic: EventTopicBoundAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Topic: EventTopicBoundAPIGateway,
|
|
|
|
Index: index,
|
|
|
|
Payload: EventPayloadConfigEntry{
|
|
|
|
Op: pbsubscribe.ConfigEntryUpdate_Upsert,
|
|
|
|
Value: gw2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range testCases {
|
|
|
|
t.Run(desc, func(t *testing.T) {
|
|
|
|
buf := &snapshotAppender{}
|
|
|
|
|
|
|
|
idx, err := store.BoundAPIGatewaySnapshot(stream.SubscribeRequest{Subject: tc.subject}, buf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, index, idx)
|
|
|
|
require.Len(t, buf.events, 1)
|
|
|
|
require.ElementsMatch(t, tc.events, buf.events[0])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|