forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscription_factory_impl_test.cc
490 lines (426 loc) · 23.8 KB
/
subscription_factory_impl_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#include <memory>
#include "envoy/common/exception.h"
#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/core/v3/config_source.pb.validate.h"
#include "envoy/config/core/v3/grpc_service.pb.h"
#include "envoy/config/endpoint/v3/endpoint.pb.h"
#include "envoy/stats/scope.h"
#include "source/common/config/subscription_factory_impl.h"
#include "source/common/config/xds_resource.h"
#include "test/config/v2_link_hacks.h"
#include "test/mocks/config/mocks.h"
#include "test/mocks/event/mocks.h"
#include "test/mocks/filesystem/mocks.h"
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/protobuf/mocks.h"
#include "test/mocks/server/instance.h"
#include "test/mocks/stats/mocks.h"
#include "test/mocks/upstream/cluster_manager.h"
#include "test/test_common/environment.h"
#include "test/test_common/logging.h"
#include "test/test_common/test_runtime.h"
#include "test/test_common/utility.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::_;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::ReturnRef;
namespace Envoy {
namespace Config {
namespace {
enum class LegacyOrUnified { Legacy, Unified };
class SubscriptionFactoryTest : public testing::Test {
public:
SubscriptionFactoryTest()
: http_request_(&cm_.thread_local_cluster_.async_client_),
api_(Api::createApiForTest(stats_store_, random_)),
subscription_factory_(local_info_, dispatcher_, cm_, validation_visitor_, *api_, server_) {}
SubscriptionPtr
subscriptionFromConfigSource(const envoy::config::core::v3::ConfigSource& config) {
return subscription_factory_.subscriptionFromConfigSource(
config, Config::TypeUrl::get().ClusterLoadAssignment, stats_store_, callbacks_,
resource_decoder_, {});
}
SubscriptionPtr
collectionSubscriptionFromUrl(const std::string& xds_url,
const envoy::config::core::v3::ConfigSource& config) {
const auto resource_locator = XdsResourceIdentifier::decodeUrl(xds_url);
return subscription_factory_.collectionSubscriptionFromUrl(
resource_locator, config, "envoy.config.endpoint.v3.ClusterLoadAssignment", stats_store_,
callbacks_, resource_decoder_);
}
Upstream::MockClusterManager cm_;
Event::MockDispatcher dispatcher_;
NiceMock<Random::MockRandomGenerator> random_;
MockSubscriptionCallbacks callbacks_;
MockOpaqueResourceDecoder resource_decoder_;
Http::MockAsyncClientRequest http_request_;
Stats::MockIsolatedStatsStore stats_store_;
NiceMock<LocalInfo::MockLocalInfo> local_info_;
NiceMock<Server::MockInstance> server_;
NiceMock<ProtobufMessage::MockValidationVisitor> validation_visitor_;
Api::ApiPtr api_;
SubscriptionFactoryImpl subscription_factory_;
};
class SubscriptionFactoryTestUnifiedOrLegacyMux
: public SubscriptionFactoryTest,
public testing::WithParamInterface<LegacyOrUnified> {
public:
SubscriptionFactoryTestUnifiedOrLegacyMux() {
if (GetParam() == LegacyOrUnified::Unified) {
scoped_runtime_.mergeValues({{"envoy.reloadable_features.unified_mux", "true"}});
}
}
TestScopedRuntime scoped_runtime_;
};
class SubscriptionFactoryTestApiConfigSource
: public SubscriptionFactoryTest,
public testing::WithParamInterface<envoy::config::core::v3::ApiConfigSource::ApiType> {};
INSTANTIATE_TEST_SUITE_P(SubscriptionFactoryTestUnifiedOrLegacyMux,
SubscriptionFactoryTestUnifiedOrLegacyMux,
::testing::Values(LegacyOrUnified::Unified, LegacyOrUnified::Legacy));
TEST_F(SubscriptionFactoryTest, NoConfigSpecifier) {
envoy::config::core::v3::ConfigSource config;
EXPECT_THROW_WITH_MESSAGE(
subscriptionFromConfigSource(config), EnvoyException,
"Missing config source specifier in envoy::config::core::v3::ConfigSource");
}
TEST_F(SubscriptionFactoryTest, RestClusterEmpty) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscriptionFromConfigSource(config), EnvoyException,
"API configs must have either a gRPC service or a cluster name defined:");
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcClusterEmpty) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscriptionFromConfigSource(config), EnvoyException,
"API configs must have either a gRPC service or a cluster name defined:");
}
TEST_F(SubscriptionFactoryTest, RestClusterSingleton) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
config.mutable_api_config_source()->set_transport_api_version(envoy::config::core::v3::V3);
config.mutable_api_config_source()->mutable_refresh_delay()->set_seconds(1);
config.mutable_api_config_source()->add_cluster_names("static_cluster");
primary_clusters.insert("static_cluster");
EXPECT_CALL(dispatcher_, createTimer_(_));
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
subscriptionFromConfigSource(config);
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcClusterSingleton) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
config.mutable_api_config_source()->set_transport_api_version(envoy::config::core::v3::V3);
config.mutable_api_config_source()->mutable_refresh_delay()->set_seconds(1);
config.mutable_api_config_source()->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster");
primary_clusters.insert("static_cluster");
envoy::config::core::v3::GrpcService expected_grpc_service;
expected_grpc_service.mutable_envoy_grpc()->set_cluster_name("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_CALL(cm_, grpcAsyncClientManager()).WillOnce(ReturnRef(cm_.async_client_manager_));
EXPECT_CALL(cm_.async_client_manager_,
factoryForGrpcService(ProtoEq(expected_grpc_service), _, _))
.WillOnce(Invoke([](const envoy::config::core::v3::GrpcService&, Stats::Scope&, bool) {
auto async_client_factory = std::make_unique<Grpc::MockAsyncClientFactory>();
EXPECT_CALL(*async_client_factory, createUncachedRawAsyncClient()).WillOnce(Invoke([] {
return std::make_unique<Grpc::MockAsyncClient>();
}));
return async_client_factory;
}));
EXPECT_CALL(dispatcher_, createTimer_(_));
subscriptionFromConfigSource(config);
}
TEST_F(SubscriptionFactoryTest, RestClusterMultiton) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
config.mutable_api_config_source()->add_cluster_names("static_cluster_foo");
primary_clusters.insert("static_cluster_foo");
config.mutable_api_config_source()->add_cluster_names("static_cluster_bar");
primary_clusters.insert("static_cluster_bar");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscriptionFromConfigSource(config), EnvoyException,
fmt::format("{} must have a singleton cluster name specified:",
config.mutable_api_config_source()->GetTypeName()));
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcClusterMultiton) {
envoy::config::core::v3::ConfigSource config;
Upstream::ClusterManager::ClusterSet primary_clusters;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
config.mutable_api_config_source()->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster_foo");
primary_clusters.insert("static_cluster_foo");
config.mutable_api_config_source()->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster_bar");
primary_clusters.insert("static_cluster_bar");
EXPECT_CALL(cm_, grpcAsyncClientManager()).WillRepeatedly(ReturnRef(cm_.async_client_manager_));
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscriptionFromConfigSource(config), EnvoyException,
fmt::format("{}::.DELTA_.GRPC must have a "
"single gRPC service specified:",
config.mutable_api_config_source()->GetTypeName()));
}
TEST_F(SubscriptionFactoryTest, FilesystemSubscription) {
envoy::config::core::v3::ConfigSource config;
std::string test_path = TestEnvironment::temporaryDirectory();
config.set_path(test_path);
auto* watcher = new Filesystem::MockWatcher();
EXPECT_CALL(dispatcher_, createFilesystemWatcher_()).WillOnce(Return(watcher));
EXPECT_CALL(*watcher, addWatch(test_path, _, _));
EXPECT_CALL(callbacks_, onConfigUpdateFailed(_, _));
subscriptionFromConfigSource(config)->start({"foo"});
}
TEST_F(SubscriptionFactoryTest, FilesystemSubscriptionNonExistentFile) {
envoy::config::core::v3::ConfigSource config;
config.set_path("/blahblah");
EXPECT_THROW_WITH_MESSAGE(subscriptionFromConfigSource(config)->start({"foo"}), EnvoyException,
"paths must refer to an existing path in the system: "
"'/blahblah' does not exist")
}
TEST_F(SubscriptionFactoryTest, FilesystemCollectionSubscription) {
std::string test_path = TestEnvironment::temporaryDirectory();
auto* watcher = new Filesystem::MockWatcher();
EXPECT_CALL(dispatcher_, createFilesystemWatcher_()).WillOnce(Return(watcher));
EXPECT_CALL(*watcher, addWatch(test_path, _, _));
EXPECT_CALL(callbacks_, onConfigUpdateFailed(_, _));
// Unix paths start with /, Windows with c:/.
const std::string file_path = test_path[0] == '/' ? test_path.substr(1) : test_path;
collectionSubscriptionFromUrl(fmt::format("file:///{}", file_path), {})->start({});
}
TEST_F(SubscriptionFactoryTest, FilesystemCollectionSubscriptionNonExistentFile) {
EXPECT_THROW_WITH_MESSAGE(collectionSubscriptionFromUrl("file:///blahblah", {})->start({}),
EnvoyException,
"paths must refer to an existing path in the system: "
"'/blahblah' does not exist");
}
TEST_F(SubscriptionFactoryTest, HttpSubscriptionCustomRequestTimeout) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_cluster_names("static_cluster");
api_config_source->mutable_refresh_delay()->set_seconds(1);
api_config_source->mutable_request_timeout()->set_seconds(5);
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(2);
cm_.initializeThreadLocalClusters({"static_cluster"});
EXPECT_CALL(cm_, getThreadLocalCluster("static_cluster"));
EXPECT_CALL(cm_.thread_local_cluster_, httpAsyncClient());
EXPECT_CALL(
cm_.thread_local_cluster_.async_client_,
send_(_, _, Http::AsyncClient::RequestOptions().setTimeout(std::chrono::milliseconds(5000))));
subscriptionFromConfigSource(config)->start({"static_cluster"});
}
TEST_F(SubscriptionFactoryTest, HttpSubscription) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_cluster_names("static_cluster");
api_config_source->mutable_refresh_delay()->set_seconds(1);
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(2);
cm_.initializeThreadLocalClusters({"static_cluster"});
EXPECT_CALL(cm_, getThreadLocalCluster("static_cluster"));
EXPECT_CALL(cm_.thread_local_cluster_, httpAsyncClient());
EXPECT_CALL(cm_.thread_local_cluster_.async_client_, send_(_, _, _))
.WillOnce(Invoke([this](Http::RequestMessagePtr& request, Http::AsyncClient::Callbacks&,
const Http::AsyncClient::RequestOptions&) {
EXPECT_EQ("POST", request->headers().getMethodValue());
EXPECT_EQ("static_cluster", request->headers().getHostValue());
EXPECT_EQ("/v3/discovery:endpoints", request->headers().getPathValue());
return &http_request_;
}));
EXPECT_CALL(http_request_, cancel());
subscriptionFromConfigSource(config)->start({"static_cluster"});
}
// Confirm error when no refresh delay is set (not checked by schema).
TEST_F(SubscriptionFactoryTest, HttpSubscriptionNoRefreshDelay) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::REST);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_cluster_names("static_cluster");
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_MESSAGE(subscriptionFromConfigSource(config)->start({"static_cluster"}),
EnvoyException,
"refresh_delay is required for REST API configuration sources");
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcSubscription) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name("static_cluster");
envoy::config::core::v3::GrpcService expected_grpc_service;
expected_grpc_service.mutable_envoy_grpc()->set_cluster_name("static_cluster");
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_CALL(cm_, grpcAsyncClientManager()).WillOnce(ReturnRef(cm_.async_client_manager_));
EXPECT_CALL(cm_.async_client_manager_,
factoryForGrpcService(ProtoEq(expected_grpc_service), _, _))
.WillOnce(Invoke([](const envoy::config::core::v3::GrpcService&, Stats::Scope&, bool) {
auto async_client_factory = std::make_unique<Grpc::MockAsyncClientFactory>();
EXPECT_CALL(*async_client_factory, createUncachedRawAsyncClient()).WillOnce(Invoke([] {
return std::make_unique<NiceMock<Grpc::MockAsyncClient>>();
}));
return async_client_factory;
}));
EXPECT_CALL(random_, random());
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(3);
// onConfigUpdateFailed() should not be called for gRPC stream connection failure
EXPECT_CALL(callbacks_, onConfigUpdateFailed(_, _)).Times(0);
subscriptionFromConfigSource(config)->start({"static_cluster"});
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcCollectionSubscriptionBadType) {
EXPECT_THROW_WITH_MESSAGE(collectionSubscriptionFromUrl("xdstp:///foo", {})->start({}),
EnvoyException,
"xdstp:// type does not match "
"envoy.config.endpoint.v3.ClusterLoadAssignment in xdstp:///foo");
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcCollectionSubscriptionUnsupportedApiType) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name("static_cluster");
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
std::string expected_config_text = R"pb(api_type: GRPC)pb";
envoy::config::core::v3::ApiConfigSource expected_config_proto;
Protobuf::TextFormat::ParseFromString(expected_config_text, &expected_config_proto);
EXPECT_THROW_WITH_REGEX(
collectionSubscriptionFromUrl(
"xdstp://foo/envoy.config.endpoint.v3.ClusterLoadAssignment/bar", config)
->start({}),
EnvoyException,
fmt::format("Unknown xdstp:// transport API type in {}",
expected_config_proto.DebugString()));
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux,
GrpcCollectionSubscriptionUnsupportedConfigSpecifierType) {
envoy::config::core::v3::ConfigSource config;
config.set_path("/path/foo/bar");
EXPECT_THROW_WITH_REGEX(
collectionSubscriptionFromUrl(
"xdstp://foo/envoy.config.endpoint.v3.ClusterLoadAssignment/bar", config)
->start({}),
EnvoyException,
"Missing or not supported config source specifier in envoy::config::core::v3::ConfigSource "
"for a collection. Only ADS and gRPC in delta-xDS mode are supported.");
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcCollectionAggregatedSubscription) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::AGGREGATED_DELTA_GRPC);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name("static_cluster");
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
GrpcMuxSharedPtr ads_mux = std::make_shared<NiceMock<MockGrpcMux>>();
EXPECT_CALL(cm_, adsMux()).WillOnce(Return(ads_mux));
EXPECT_CALL(dispatcher_, createTimer_(_));
// onConfigUpdateFailed() should not be called for gRPC stream connection failure
EXPECT_CALL(callbacks_, onConfigUpdateFailed(_, _)).Times(0);
collectionSubscriptionFromUrl("xdstp://foo/envoy.config.endpoint.v3.ClusterLoadAssignment/bar",
config)
->start({});
}
TEST_P(SubscriptionFactoryTestUnifiedOrLegacyMux, GrpcCollectionDeltaSubscription) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::DELTA_GRPC);
api_config_source->set_transport_api_version(envoy::config::core::v3::V3);
api_config_source->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name("static_cluster");
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_CALL(cm_, grpcAsyncClientManager()).WillOnce(ReturnRef(cm_.async_client_manager_));
EXPECT_CALL(dispatcher_, createTimer_(_)).Times(3);
// onConfigUpdateFailed() should not be called for gRPC stream connection failure
EXPECT_CALL(callbacks_, onConfigUpdateFailed(_, _)).Times(0);
collectionSubscriptionFromUrl("xdstp://foo/envoy.config.endpoint.v3.ClusterLoadAssignment/bar",
config)
->start({});
}
// Use of the V2 transport fails by default.
TEST_F(SubscriptionFactoryTest, LogWarningOnDeprecatedV2Transport) {
envoy::config::core::v3::ConfigSource config;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
config.mutable_api_config_source()->set_transport_api_version(
envoy::config::core::v3::ApiVersion::V2);
config.mutable_api_config_source()->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster");
TestScopedRuntime scoped_runtime;
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscription_factory_.subscriptionFromConfigSource(
config, Config::TypeUrl::get().ClusterLoadAssignment, stats_store_,
callbacks_, resource_decoder_, {}),
EnvoyException,
"V2 .and AUTO. xDS transport protocol versions are deprecated in");
}
// Use of AUTO transport fails by default. This will encourage folks to upgrade to explicit V3.
TEST_F(SubscriptionFactoryTest, LogWarningOnDeprecatedAutoTransport) {
envoy::config::core::v3::ConfigSource config;
config.mutable_api_config_source()->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
config.mutable_api_config_source()->set_transport_api_version(
envoy::config::core::v3::ApiVersion::AUTO);
config.mutable_api_config_source()->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster");
TestScopedRuntime scoped_runtime;
Upstream::ClusterManager::ClusterSet primary_clusters;
primary_clusters.insert("static_cluster");
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_REGEX(subscription_factory_.subscriptionFromConfigSource(
config, Config::TypeUrl::get().ClusterLoadAssignment, stats_store_,
callbacks_, resource_decoder_, {}),
EnvoyException,
"V2 .and AUTO. xDS transport protocol versions are deprecated in");
}
INSTANTIATE_TEST_SUITE_P(SubscriptionFactoryTestApiConfigSource,
SubscriptionFactoryTestApiConfigSource,
::testing::Values(envoy::config::core::v3::ApiConfigSource::REST,
envoy::config::core::v3::ApiConfigSource::GRPC));
TEST_P(SubscriptionFactoryTestApiConfigSource, NonExistentCluster) {
envoy::config::core::v3::ConfigSource config;
auto* api_config_source = config.mutable_api_config_source();
api_config_source->set_api_type(GetParam());
if (api_config_source->api_type() == envoy::config::core::v3::ApiConfigSource::GRPC) {
api_config_source->add_grpc_services()->mutable_envoy_grpc()->set_cluster_name(
"static_cluster");
} else {
api_config_source->add_cluster_names("static_cluster");
}
Upstream::ClusterManager::ClusterSet primary_clusters;
EXPECT_CALL(cm_, primaryClusters()).WillOnce(ReturnRef(primary_clusters));
EXPECT_THROW_WITH_MESSAGE(subscriptionFromConfigSource(config)->start({"static_cluster"}),
EnvoyException,
fmt::format("{} must have a statically defined "
"non-EDS cluster: 'static_cluster' does not exist, was "
"added via api, or is an EDS cluster",
api_config_source->GetTypeName()));
}
} // namespace
} // namespace Config
} // namespace Envoy