forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_manager_impl_test.cc
67 lines (52 loc) · 1.59 KB
/
init_manager_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
#include "server/init_manager_impl.h"
#include "test/mocks/common.h"
#include "test/mocks/init/mocks.h"
#include "gmock/gmock.h"
using testing::_;
using testing::InSequence;
using testing::Invoke;
namespace Envoy {
namespace Server {
class InitManagerImplTest : public testing::Test {
public:
InitManagerImpl manager_;
ReadyWatcher initialized_;
};
TEST_F(InitManagerImplTest, NoTargets) {
EXPECT_CALL(initialized_, ready());
manager_.initialize([&]() -> void { initialized_.ready(); });
}
TEST_F(InitManagerImplTest, Targets) {
InSequence s;
Init::MockTarget target;
manager_.registerTarget(target);
EXPECT_CALL(target, initialize(_));
manager_.initialize([&]() -> void { initialized_.ready(); });
EXPECT_CALL(initialized_, ready());
target.callback_();
}
TEST_F(InitManagerImplTest, TargetRemoveWhileInitializing) {
InSequence s;
Init::MockTarget target;
manager_.registerTarget(target);
EXPECT_CALL(target, initialize(_)).WillOnce(Invoke([](std::function<void()> callback) -> void {
callback();
}));
EXPECT_CALL(initialized_, ready());
manager_.initialize([&]() -> void { initialized_.ready(); });
}
TEST_F(InitManagerImplTest, TargetAfterInitializing) {
InSequence s;
Init::MockTarget target1;
Init::MockTarget target2;
manager_.registerTarget(target1);
EXPECT_CALL(target1, initialize(_));
manager_.initialize([&]() -> void { initialized_.ready(); });
EXPECT_CALL(target2, initialize(_));
manager_.registerTarget(target2);
target2.callback_();
EXPECT_CALL(initialized_, ready());
target1.callback_();
}
} // namespace Server
} // namespace Envoy