/* * \brief Test the Azure storage rest api library * * \author Quentin Comte-Gaz * \date 10 November 2019 * \license MIT License (contact me if too restrictive) * \copyright Copyright (c) 2019 Quentin Comte-Gaz * \version 2.0 */ #define CATCH_CONFIG_RUNNER #include "catch.hpp" #include #include #include TEST_CASE("Create instance") { QString username("fakeUser"); QString pass("fakePass"); QAzureStorageRestApi api(username, pass); } TEST_CASE("Update credentials") { QString username("fakeUser"); QString pass("fakePass"); QAzureStorageRestApi api(username, pass); username = "fakeUser2"; pass = "fakePass2"; api.updateCredentials(username, pass); } TEST_CASE("Upload file (invalid path)") { QString username("fakeUser"); QString pass("fakePass"); QString path = "invalidPath"; QString container = "invalidContainer"; QString blob = "invalidBlolName"; QAzureStorageRestApi api(username, pass); QNetworkReply* reply = api.uploadFile(path, container, blob); REQUIRE(reply == nullptr); } TEST_CASE("List files") { QString username("fakeUser"); QString pass("fakePass"); QString container = "invalidContainer"; QAzureStorageRestApi api(username, pass); QNetworkReply* reply = api.listFiles(container); REQUIRE(reply != nullptr); qDebug() << "Error response: " << reply->error(); } TEST_CASE("Upload file") { QString username("fakeUser"); QString pass("fakePass"); QString path = "dummyFile.txt"; QFile file(path); REQUIRE(file.open(QIODevice::WriteOnly)); { QTextStream stream(&file); stream << "Dummy information" << endl; } file.close(); QString container = "invalidContainer"; QString blob = "invalidBlolName"; QAzureStorageRestApi api(username, pass); QNetworkReply* reply = api.uploadFile(path, container, blob); REQUIRE(reply != nullptr); qDebug() << "Error response: " << reply->error(); } TEST_CASE("Download file") { QString username("fakeUser"); QString pass("fakePass"); QString container = "invalidContainer"; QString blob = "invalidBlolName"; QAzureStorageRestApi api(username, pass); QNetworkReply* reply = api.downloadFile(container, blob); REQUIRE(reply != nullptr); qDebug() << "Error response: " << reply->error(); } TEST_CASE("Parse file list") { QByteArray fileList; QList< QMap > res = QAzureStorageRestApi::parseFileList(fileList); qDebug() << "List: " << res; REQUIRE(res.isEmpty()); fileList = QByteArray("\ \ string-value\ string-value\ int-value\ string-value\ \ \ blob-name\ true\ date-time-value\ \ date-time-value\ date-time-value\ etag\ size-in-bytes\ blob-content-type\ \ \ \ \ BlockBlob|PageBlob|AppendBlob\ tier\ locked|unlocked\ available | leased | expired | breaking | broken\ infinite | fixed\ id\ pending | success | aborted | failed \ source url\ bytes copied/bytes total\ datetime\ error string\ true\ true\ true\ datetime\ datetime\ no-of-days\ \ \ value\ \ \ \ blob-name-2\ FakeValue\ FakeValue2\ \ \ blob-prefix\ \ \ \ "); res = QAzureStorageRestApi::parseFileList(fileList); qDebug() << "Extracted blobl list: " << res; REQUIRE(!res.isEmpty()); REQUIRE(res.count() == 2); REQUIRE(res[1] == QMap({{"FakeKey", "FakeValue"}, {"FakeKey2", "FakeValue2"}, {"Name", "blob-name-2"}})); } int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); qDebug() << QString("Launching test using catch version %1.%2 - %3").arg(CATCH_VERSION_MAJOR).arg(CATCH_VERSION_MINOR).arg(CATCH_VERSION_PATCH); int result = Catch::Session().run(argc, argv); return result; }