|
@@ -885,7 +885,7 @@ TEST(Head, Positive) {
|
|
|
|
|
|
std::vector<char> bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
|
|
|
const std::string bytesAsString = "YWJjZGVmZ2g=";
|
|
|
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::headError::no_error)));
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_error)));
|
|
|
|
|
|
JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
|
@@ -932,7 +932,7 @@ TEST(Head, NoSuchFile) {
|
|
|
message["file"] = file;
|
|
|
|
|
|
std::vector<char> bytes;
|
|
|
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::headError::no_such_file)));
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_such_file)));
|
|
|
|
|
|
JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
|
@@ -957,7 +957,7 @@ TEST(Head, FileTooSmall) {
|
|
|
message["file"] = file;
|
|
|
|
|
|
std::vector<char> bytes;
|
|
|
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::headError::file_too_small)));
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
|
|
|
|
|
|
JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
|
@@ -1024,8 +1024,6 @@ TEST(Deleteme, Negative) {
|
|
|
|
|
|
JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
|
|
- std::cout << response.json << std::endl;
|
|
|
-
|
|
|
EXPECT_EQ(response.action, JsonCommander::Action::send);
|
|
|
EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
EXPECT_FALSE(response.json["accept"].asBool());
|
|
@@ -1062,4 +1060,90 @@ TEST(Deleteme, InvalidRequest) {
|
|
|
EXPECT_NE(response.json["error"].asString(), "");
|
|
|
}
|
|
|
|
|
|
+TEST(DeleteFile, Positive) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_error));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, InvalidRequest) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const int file = 3641;
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), "");
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, FileDoesNotExist) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_such_file));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, DisabledInConfig) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::not_allowed));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|