16 #include <gtest/gtest.h> 17 #include <gmock/gmock.h> 19 #include <aws/core/utils/logging/LogMacros.h> 20 #include <aws/core/utils/logging/ConsoleLogSystem.h> 37 std::experimental::filesystem::path test_folder{
"token_backups/"};
38 if (std::experimental::filesystem::exists(test_folder)) {
39 std::experimental::filesystem::remove_all(test_folder);
44 std::string backup_folder =
"token_backups/";
45 std::string kBackupFilename =
"token_store.info";
49 TEST(token_test, fail_unknown_token) {
51 EXPECT_THROW(token_store.
fail(0), std::runtime_error);
54 TEST(token_test, fail_token_twice) {
58 token_store.
fail(token);
59 EXPECT_THROW(token_store.
fail(token), std::runtime_error);
62 TEST(token_test, resolve_then_fail_token) {
66 EXPECT_THROW(token_store.
fail(token), std::runtime_error);
69 TEST(token_test, fail_then_recover_token) {
72 token_store.
fail(token);
78 TEST(token_test, resolve_unknown_token) {
80 EXPECT_THROW(token_store.
resolve(0), std::runtime_error);
83 TEST(token_test, resolve_token) {
86 auto resolved_token = token_store.
resolve(token);
90 TEST(token_test, resolve_token_twice) {
94 EXPECT_THROW(token_store.
resolve(token), std::runtime_error);
97 TEST(token_test, test_backup) {
101 auto backup = token_store.
backup();
103 EXPECT_THAT(backup, testing::ElementsAre(
kTestToken1));
106 TEST(token_test, test_backup_failed_file) {
111 token_store.
fail(token1);
112 auto backup = token_store.
backup();
114 EXPECT_THAT(backup, testing::ElementsAre(
kTestToken1));
117 TEST(token_test, test_token_restore) {
118 std::vector<FileTokenInfo> backup;
122 backup = token_store.
backup();
123 EXPECT_THAT(backup, testing::ElementsAre(
kTestToken1));
133 TEST(token_test, test_backup_two_files) {
138 auto backup = token_store.
backup();
139 EXPECT_THAT(backup, testing::UnorderedElementsAre(
kTestToken1, test_token_2));
148 std::string backup_file = options.backup_directory + kBackupFilename;
149 EXPECT_TRUE(std::experimental::filesystem::exists(backup_file));
154 std::string backup_file = options.backup_directory + kBackupFilename;
160 EXPECT_TRUE(std::experimental::filesystem::exists(backup_file));
165 EXPECT_THAT(token_store.
backup(), testing::UnorderedElementsAre(
kTestToken1, test_token_2));
171 std::string backup_file = options.backup_directory + kBackupFilename;
177 EXPECT_TRUE(std::experimental::filesystem::exists(backup_file));
180 std::ofstream token_store_file(backup_file, std::ios_base::app);
181 token_store_file <<
"some other stuff" << std::endl;
182 token_store_file.close();
187 EXPECT_THAT(token_store.
backup(), testing::UnorderedElementsAre(
kTestToken1, test_token_2));
193 int main(
int argc,
char** argv)
195 Aws::Utils::Logging::InitializeAWSLogging(
196 Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
197 "RunUnitTests", Aws::Utils::Logging::LogLevel::Trace));
198 ::testing::InitGoogleMock(&argc, argv);
199 int exitCode = RUN_ALL_TESTS();
200 Aws::Utils::Logging::ShutdownAWSLogging();
TEST_F(TokenTest, test_backup_to_disk)
void restore(const std::vector< FileTokenInfo > &file_tokens)
TEST(token_test, fail_unknown_token)
bool isTokenAvailable(const std::string &file_name) const
DataToken createToken(const std::string &file_name, const long streampos, bool is_eof)
static const FileTokenInfo kTestToken2("fake_file", 10, true)
FileTokenInfo popAvailableToken(const std::string &file_name)
static const FileTokenInfo kTestToken1("fake_file", 0, false)
FileTokenInfo fail(const DataToken &token)
int main(int argc, char **argv)
std::vector< FileTokenInfo > backup()
FileTokenInfo resolve(const DataToken &token)