16 #include <aws/core/Aws.h> 17 #include <aws/logs/model/InputLogEvent.h> 20 #include <gtest/gtest.h> 24 #define _unused(x) ((void)(x)) 32 uint32_t send_logs_call_count{};
35 std::list<Aws::CloudWatchLogs::Model::InputLogEvent>
last_logs;
37 bool fail_cw_log_group{};
38 bool fail_cw_log_stream{};
39 bool fail_cw_create_log_group{};
40 bool fail_cw_create_log_stream{};
41 bool fail_cw_init_token{};
42 bool fail_cw_send_logs{};
45 this->last_log_group =
"";
46 this->last_log_stream =
"";
47 this->send_logs_call_count = 0;
48 this->fail_cw_log_group =
false;
49 this->fail_cw_log_stream =
false;
50 this->fail_cw_create_log_group =
false;
51 this->fail_cw_create_log_stream =
false;
52 this->fail_cw_init_token =
false;
53 this->fail_cw_send_logs =
false;
61 const std::string & log_group)
override 68 const std::string & log_group,
const std::string & log_stream,
69 Aws::CloudWatchLogs::Model::LogStream * log_stream_object)
override 78 const std::string & log_group)
override 86 const std::string & log_group,
const std::string & log_stream)
override 94 const std::string & log_group,
95 const std::string & log_stream,
96 Aws::String & next_token)
override {
100 if (fail_cw_init_token) {
104 next_token = Aws::String(
"this token has been set");
110 Aws::String & next_token,
111 const std::string & last_log_group,
112 const std::string & last_log_stream,
113 std::list<Aws::CloudWatchLogs::Model::InputLogEvent> & logs)
override 115 this->last_log_group = last_log_group;
116 this->last_log_stream = last_log_stream;
117 this->last_logs = logs;
118 this->send_logs_call_count++;
119 this->next_token = next_token;
133 std::list<Aws::CloudWatchLogs::Model::InputLogEvent>
logs_list_;
140 EXPECT_EQ(ServiceState::CREATED, publisher_->getState());
141 EXPECT_EQ(
true, publisher_->start());
142 EXPECT_EQ(ServiceState::STARTED, publisher_->getState());
148 logs_list_.emplace_back();
149 logs_list_.emplace_back();
150 EXPECT_FALSE(logs_list_.empty());
152 mock_cw_ = std::make_shared<MockCloudWatchFacade>();
153 std::shared_ptr<Aws::CloudWatchLogs::Utils::CloudWatchLogsFacade> cw = mock_cw_;
154 publisher_ = std::make_shared<LogPublisher>(
"test_log_group",
"test_log_stream", cw);
160 publisher_->shutdown();
173 std::list<Aws::CloudWatchLogs::Model::InputLogEvent> empty_list;
174 EXPECT_EQ(Aws::DataFlow::UploadStatus::INVALID_DATA, publisher_->attemptPublish(empty_list));
175 EXPECT_EQ(PublisherState::NOT_CONNECTED, publisher_->getPublisherState());
182 EXPECT_EQ(Aws::DataFlow::UploadStatus::SUCCESS, publisher_->attemptPublish(logs_list_));
183 EXPECT_EQ(PublisherState::CONNECTED, publisher_->getPublisherState());
191 EXPECT_EQ(Aws::DataFlow::UploadStatus::SUCCESS, publisher_->attemptPublish(logs_list_));
192 EXPECT_EQ(PublisherState::CONNECTED, publisher_->getPublisherState());
193 EXPECT_EQ(1u, mock_cw_->send_logs_call_count);
201 mock_cw_->fail_cw_log_group =
true;
202 mock_cw_->fail_cw_create_log_group =
true;
203 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
212 mock_cw_->fail_cw_log_stream =
true;
213 mock_cw_->fail_cw_create_log_stream =
true;
214 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
223 mock_cw_->fail_cw_init_token =
true;
224 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
233 mock_cw_->fail_cw_send_logs =
true;
234 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
241 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
242 EXPECT_TRUE(publisher_->shutdown());
243 EXPECT_EQ(Aws::DataFlow::UploadStatus::FAIL, publisher_->attemptPublish(logs_list_));
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors CheckLogGroupExists(const std::string &log_group) override
Check if a log group exists.
std::shared_ptr< MockCloudWatchFacade > mock_cw_
This test requires a fixture to init and shutdown the SDK or else it causes seg faults when trying to...
std::shared_ptr< LogPublisher > publisher_
std::list< Aws::CloudWatchLogs::Model::InputLogEvent > last_logs
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors CheckLogStreamExists(const std::string &log_group, const std::string &log_stream, Aws::CloudWatchLogs::Model::LogStream *log_stream_object) override
Check if a log stream in a log group exists.
This class is a simple Facade over the CloudWatch client. This class is a very small abstraction over...
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors CreateLogStream(const std::string &log_group, const std::string &log_stream) override
Creates a log stream in the specified log group.
Contains Error handling functionality for ROS AWS CloudWatch Logs libraries.
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors GetLogStreamToken(const std::string &log_group, const std::string &log_stream, Aws::String &next_token) override
Gets the next sequence token to use for sending logs to cloudwatch.
std::string last_log_stream
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors SendLogsToCloudWatch(Aws::String &next_token, const std::string &last_log_group, const std::string &last_log_stream, std::list< Aws::CloudWatchLogs::Model::InputLogEvent > &logs) override
std::list< Aws::CloudWatchLogs::Model::InputLogEvent > logs_list_
TEST_F(TestLogPublisherFixture, Sanity)
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors CreateLogGroup(const std::string &log_group) override
Creates a log group.
ROSCloudWatchLogsErrors
Defines error return codes for functions This enum defines standard error codes that will be returned...
std::string last_log_group