File: SdkTestSyncNodeAttribute_test.cpp

package info (click to toggle)
megacmd 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 32,592 kB
  • sloc: cpp: 326,437; ansic: 34,524; python: 4,630; java: 3,965; sh: 2,869; objc: 2,459; makefile: 197; xml: 113
file content (104 lines) | stat: -rw-r--r-- 4,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * @file SdkTestSyncNodeAttribute.cpp
 * @brief This file is expected to contain SdkTestSyncNodeAttributes class definition and tests.
 */

#ifdef ENABLE_SYNC

#include "integration_test_utils.h"
#include "mega/utils.h"
#include "megautils.h"
#include "sdk_test_utils.h"
#include "SdkTestSyncNodesOperations.h"

#include <gmock/gmock.h>

using namespace sdk_test;
using namespace testing;

class SdkTestSyncNodeAttributes: public SdkTestSyncNodesOperations
{
public:
    const std::vector<NodeInfo>& getElements() const override
    {
        static const std::vector<NodeInfo> ELEMENTS{DirNodeInfo(DEFAULT_SYNC_REMOTE_PATH)
                                                        .addChild(FileNodeInfo("test.txt")
                                                                      .setSize(10)
                                                                      .setFav(true)
                                                                      .setDescription("description")
                                                                      .setTags({"tag1", "tag2"}))};
        return ELEMENTS;
    }

    /**
     * @brief Waits until the test file got sync to cloud - checking if size is same.
     *
     * Asserts false if a timeout is exceeded.
     */
    void waitForFileToSync(const std::string_view fileName)
    {
        const auto areLocalAndCloudSynched = [this, fileName]() -> bool
        {
            const string filePath = "dir1/" + string(fileName);
            const auto syncNode = getNodeByPath(filePath);
            const auto syncNodeSize =
                static_cast<std::uintmax_t>(megaApi[0]->getSize(syncNode.get()));
            return fs::file_size(getLocalTmpDir() / std::string(fileName)) == syncNodeSize;
        };
        ASSERT_TRUE(waitFor(areLocalAndCloudSynched, COMMON_TIMEOUT, 10s));
    }
};

/**
 * @brief SdkTestSyncNodeAttributes.VerifyAttributeAfterSync
 *
 * Check file attributes consistency after sync completes
 */
TEST_F(SdkTestSyncNodeAttributes, VerifyAttributeAfterSync)
{
    static const auto logPre = getLogPrefix();
    const auto remoteFilePath = "/SDK_TEST_SYNC_NODE_OPERATIONS_AUX_DIR/dir1/test.txt";

    LOG_verbose << logPre << "Ensuring sync is running on dir1";
    ASSERT_NO_FATAL_FAILURE(ensureSyncNodeIsRunning("dir1"));

    LOG_verbose << logPre << "Waiting for sync remote and local roots to have the same content";
    ASSERT_NO_FATAL_FAILURE(waitForSyncToMatchCloudAndLocal());

    LOG_verbose << logPre << "Check if the contents match expectations";
    ASSERT_NO_FATAL_FAILURE(checkCurrentLocalMatchesOriginal("dir1"));

    const auto megaNode = megaApi[0]->getNodeByPath(remoteFilePath, nullptr);
    const auto description = megaNode->getDescription();
    const auto lable = megaNode->getLabel();
    const auto fav = megaNode->isFavourite();
    const auto tags = megaNode->getTags();

    LOG_verbose << logPre << "Update the existing file size by appending extra data locally";
    const auto localTestFilePath = getLocalTmpDir() / "test.txt";
    appendToFile(localTestFilePath, 20);

    LOG_verbose << logPre << "Ensuring sync is running on dir1";
    ASSERT_NO_FATAL_FAILURE(ensureSyncNodeIsRunning("dir1"));

    LOG_verbose << logPre << "Waiting for sync remote and local nodes to have the same size";
    ASSERT_NO_FATAL_FAILURE(waitForFileToSync("test.txt"));

    const auto afterSync = megaApi[0]->getNodeByPath(remoteFilePath, nullptr);
    const auto asDescription =
        afterSync->getDescription() == nullptr ? "" : afterSync->getDescription();
    const auto asLable = afterSync->getLabel();
    const auto asFav = afterSync->isFavourite();
    const auto asTags = afterSync->getTags();

    ASSERT_STREQ(description, asDescription) << "Description attribute mismatched after sync";
    ASSERT_EQ(lable, asLable) << "Lable attribute mismatched after sync";
    ASSERT_EQ(fav, asFav) << "Favourite attribute mismatched after sync";
    ASSERT_EQ(tags->size(), asTags->size()) << "Node tags are not same after sync";
    for (int i = 0; i < tags->size(); i++)
    {
        ASSERT_STREQ(tags->get(i), asTags->get(i)) << "Tag attribute mismatched after sync";
    }
}

#endif