file_manager_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #include <iostream>
17 #include <fstream>
18 #include <cstdio>
19 #include <experimental/filesystem>
20 
21 #include <gtest/gtest.h>
22 #include <gmock/gmock.h>
23 #include <aws/logs/model/InputLogEvent.h>
24 #include <aws/core/utils/memory/stl/AWSString.h>
25 #include <aws/core/utils/logging/ConsoleLogSystem.h>
26 #include <aws/core/utils/logging/AWSLogging.h>
27 
30 #include <file_management/utils/log_file_manager.h>
31 
32 
33 using namespace Aws::CloudWatchLogs;
34 using namespace Aws::FileManagement;
35 
36 class FileManagerTest : public ::testing::Test {
37 public:
38  void SetUp() override
39  {
40  }
41 
42  void TearDown() override
43  {
44  std::experimental::filesystem::path storage_path(options.storage_directory);
45  std::experimental::filesystem::remove_all(storage_path);
46  }
47 
48 protected:
49  FileManagerStrategyOptions options{"test", "log_tests/", ".log", 1024*1024, 1024*1024};
50 };
51 
55 TEST_F(FileManagerTest, file_manager_write) {
56  std::shared_ptr<FileManagerStrategy> file_manager_strategy = std::make_shared<FileManagerStrategy>(options);
57  LogFileManager file_manager(file_manager_strategy);
58  LogEventCollection log_data;
59  Aws::CloudWatchLogs::Model::InputLogEvent input_event;
60  input_event.SetTimestamp(0);
61  input_event.SetMessage("Hello my name is foo");
62  log_data.push_back(input_event);
63  file_manager.write(log_data);
64  std::string line;
65  file_manager_strategy->read(line);
66  EXPECT_EQ(line, "{\"timestamp\":0,\"message\":\"Hello my name is foo\"}");
67 }
68 
69 int main(int argc, char** argv)
70 {
71  Aws::Utils::Logging::InitializeAWSLogging(
72  Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
73  "RunUnitTests", Aws::Utils::Logging::LogLevel::Trace));
74  ::testing::InitGoogleMock(&argc, argv);
75  int exitCode = RUN_ALL_TESTS();
76  Aws::Utils::Logging::ShutdownAWSLogging();
77  return exitCode;
78 }
79 
void SetUp() override
int main(int argc, char **argv)
TEST_F(FileManagerTest, file_manager_write)
void TearDown() override


cloudwatch_logs_common
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:24