|
1 | 1 | #include "source/extensions/dynamic_modules/abi/abi.h" |
2 | 2 |
|
| 3 | +#include "test/mocks/server/server_factory_context.h" |
3 | 4 | #include "test/test_common/utility.h" |
4 | 5 |
|
5 | 6 | #include "gtest/gtest.h" |
6 | 7 |
|
| 8 | +using testing::Return; |
| 9 | + |
7 | 10 | namespace Envoy { |
8 | 11 | namespace Extensions { |
9 | 12 | namespace DynamicModules { |
10 | 13 | namespace { |
11 | 14 |
|
| 15 | +// ============================================================================= |
| 16 | +// Validation Mode Tests |
| 17 | +// ============================================================================= |
| 18 | + |
| 19 | +TEST(CommonAbiImplTest, IsValidationModeReturnsTrueInValidateMode) { |
| 20 | + testing::NiceMock<Server::Configuration::MockServerFactoryContext> context; |
| 21 | + ON_CALL(context.options_, mode()).WillByDefault(Return(Server::Mode::Validate)); |
| 22 | + |
| 23 | + ScopedThreadLocalServerContextSetter setter(context); |
| 24 | + EXPECT_TRUE(envoy_dynamic_module_callback_is_validation_mode()); |
| 25 | +} |
| 26 | + |
| 27 | +TEST(CommonAbiImplTest, IsValidationModeReturnsFalseInServeMode) { |
| 28 | + testing::NiceMock<Server::Configuration::MockServerFactoryContext> context; |
| 29 | + ON_CALL(context.options_, mode()).WillByDefault(Return(Server::Mode::Serve)); |
| 30 | + |
| 31 | + ScopedThreadLocalServerContextSetter setter(context); |
| 32 | + EXPECT_FALSE(envoy_dynamic_module_callback_is_validation_mode()); |
| 33 | +} |
| 34 | + |
| 35 | +TEST(CommonAbiImplTest, IsValidationModeReturnsFalseInInitOnlyMode) { |
| 36 | + testing::NiceMock<Server::Configuration::MockServerFactoryContext> context; |
| 37 | + ON_CALL(context.options_, mode()).WillByDefault(Return(Server::Mode::InitOnly)); |
| 38 | + |
| 39 | + ScopedThreadLocalServerContextSetter setter(context); |
| 40 | + EXPECT_FALSE(envoy_dynamic_module_callback_is_validation_mode()); |
| 41 | +} |
| 42 | + |
| 43 | +// ============================================================================= |
| 44 | +// Function Registry Tests |
| 45 | +// ============================================================================= |
| 46 | + |
12 | 47 | // Test registering and retrieving a function. |
13 | 48 | TEST(CommonAbiImplTest, FunctionRegistryRegisterAndGet) { |
14 | 49 | auto fn = [](int x) { return x + 1; }; |
|
0 commit comments