File: SdkTestSyncPrevalidation_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 (146 lines) | stat: -rw-r--r-- 6,243 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
 * @file SdkTestSyncPrevalidation_test.cpp
 * @brief This file is expected to contain the SdkTestSyncPrevalidation test cases.
 *
 * Test cases testing failures cover one possible failure for different code flows; i.e., some
 * failures can happen during precondition checks, others are specific for sync type (like an error
 * returned from MegaClient::prepareBackup()), and others are part of the
 * MegaClient::checkSyncConfig().
 */

#ifdef ENABLE_SYNC

#include "SdkTestSyncPrevalidation.h"

using namespace sdk_test;

/**
 * @test SdkTestSyncPrevalidation.PrevalidateSyncOK
 *
 * 1. Prevalidates a sync that should work correctly.
 * 2. Creates the sync afterwards for double-checking: it should work as well.
 */
TEST_F(SdkTestSyncPrevalidation, PrevalidateSyncOK)
{
    static const auto logPre = getLogPrefix();

    LOG_verbose << logPre << "Prevalidating sync";
    SyncFolderExpectations prevalidateExpectations{MegaRequest::TYPE_ADD_SYNC_PREVALIDATION,
                                                   API_OK,
                                                   MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(prevalidateSync(std::move(prevalidateExpectations)));

    LOG_verbose << logPre << "Sync prevalidated OK. Creating sync: it should work as well";
    ASSERT_NO_FATAL_FAILURE(createSync());
}

/**
 * @test SdkTestSyncPrevalidation.PrevalidateSyncFailureAlreadyExists
 *
 * 1. Creates a sync.
 * 2. Prevalidates the sync: it should fail as it already exists.
 * 3. Tries to create the sync afterwards for double checking: it should fail as well.
 */
TEST_F(SdkTestSyncPrevalidation, PrevalidateSyncFailureAlreadyExists)
{
    static const auto logPre = getLogPrefix();

    LOG_verbose << logPre << "Creating sync";
    ASSERT_NO_FATAL_FAILURE(createSync());

    LOG_verbose << logPre << "Prevalidating sync over an existing sync: should fail";
    SyncFolderExpectations prevalidateExpectations{MegaRequest::TYPE_ADD_SYNC_PREVALIDATION,
                                                   API_EEXIST,
                                                   MegaSync::ACTIVE_SYNC_SAME_PATH};
    ASSERT_NO_FATAL_FAILURE(prevalidateSync(std::move(prevalidateExpectations)));

    LOG_verbose << logPre
                << "Trying to create a sync over an existing sync: should have same result as with "
                   "prevalidation";
    SyncFolderExpectations expectations{MegaRequest::TYPE_ADD_SYNC,
                                        API_EEXIST,
                                        MegaSync::ACTIVE_SYNC_SAME_PATH};
    ASSERT_NO_FATAL_FAILURE(createSync(std::move(expectations)));
}

/**
 * @test SdkTestSyncPrevalidation.PrevalidateSyncFailureNoRemotePath
 *
 * 1. Prevalidates a sync with a remote path that doesn't exist.
 * 2. Tries to create the sync afterwards for double checking: it should fail as well.
 */
TEST_F(SdkTestSyncPrevalidation, PrevalidateSyncFailureNoRemotePath)
{
    static const auto logPre = getLogPrefix();

    const std::string fakeRemotePath{"fakePath"};
    LOG_verbose << logPre << "Prevalidating sync over with a non existing remote path";
    SyncFolderExpectations prevalidateExpectations{MegaRequest::TYPE_ADD_SYNC_PREVALIDATION,
                                                   API_EARGS,
                                                   MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(prevalidateSync(std::move(prevalidateExpectations), fakeRemotePath));

    LOG_verbose << logPre
                << "Trying to create a sync with a non existing remote path: should have same "
                   "result as with prevalidation";
    SyncFolderExpectations expectations{MegaRequest::TYPE_ADD_SYNC,
                                        API_EARGS,
                                        MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(createSync(std::move(expectations), fakeRemotePath));
}

/**
 * @test SdkTestSyncPrevalidation.PrevalidateBackupOK
 *
 * 1. Prevalidates a backup that should work correctly.
 * 2. Creates the backup afterwards for double-checking: it should work as well.
 */
TEST_F(SdkTestSyncPrevalidation, PrevalidateBackupOK)
{
    static const auto logPre = getLogPrefix();

    LOG_verbose << logPre << "Prevalidating backup";
    SyncFolderExpectations prevalidateExpectations{MegaRequest::TYPE_ADD_SYNC_PREVALIDATION,
                                                   API_OK,
                                                   MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(prevalidateBackup(std::move(prevalidateExpectations)));

    LOG_verbose << logPre << "Backup prevalidated OK. Creating sync: it should work as well";
    ASSERT_NO_FATAL_FAILURE(createBackup());
}

/**
 * @test SdkTestSyncPrevalidation.PrevalidateSyncFailureAlreadyExists
 *
 * 1. Creates a backup.
 * 2. Prevalidates the backup: it should fail as it already exists.
 * 3. Tries to create the backup afterwards for double checking: it should fail as well.
 *
 * @note Unlike PrevalidateSyncFailureAlreadyExists, whose checks are done at
 * MegaClient::checkSyncConfig(), this logic is checked within MegaClient::preparebackup() (called
 * before checkSyncConfig()).
 */
TEST_F(SdkTestSyncPrevalidation, PrevalidateBackupFailureAlreadyExists)
{
    static const auto logPre = getLogPrefix();

    LOG_verbose << logPre << "Creating backup";
    ASSERT_NO_FATAL_FAILURE(createBackup());

    LOG_verbose << logPre << "Prevalidating backup over an existing backup: should fail";
    SyncFolderExpectations prevalidateExpectations{MegaRequest::TYPE_ADD_SYNC_PREVALIDATION,
                                                   API_EACCESS,
                                                   MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(prevalidateBackup(std::move(prevalidateExpectations)));

    LOG_verbose
        << logPre
        << "Trying to create a backup over an existing backup: should have same result as with "
           "prevalidation";
    SyncFolderExpectations expectations{MegaRequest::TYPE_ADD_SYNC,
                                        API_EACCESS,
                                        MegaSync::NO_SYNC_ERROR};
    ASSERT_NO_FATAL_FAILURE(createBackup(std::move(expectations)));
}

#endif // ENABLE_SYNC